Found 34489 Articles for Programming

How to Find LCM using Python?

Jayashree
Updated on 02-Mar-2020 05:16:37

687 Views

 LCM (Least common multiple) of two (or more) numbers is a number which is the smallest number that is divisible by both (or all).First we find the larger number of two given numbers. Starting from it we try and find the first number that is divisible by both, which is LCMExamplex=12 y=20 if x > y:      greater = x   else:      greater = y   while(True):      if((greater % x == 0) and (greater % y == 0)):           lcm = greater           break       greater += 1 print ("LCM of {} and {}={}".format(x,y,lcm))OutputThe result is −LCM of 12 and 20=60

How to Find the Sum of Natural Numbers using Python?

Jayashree
Updated on 21-Feb-2020 12:54:53

1K+ Views

You can use while loop to successively increment value of a variable i by one and adding it cumulatively.s,i=0,0 n=10 while i

How to Find Factorial of Number Using Recursion in Python?

Jayashree
Updated on 21-Feb-2020 12:54:14

681 Views

Factorial of a number is product of all numbers from 1 to that number.A function is called a recursive function if it calls itself.In following program factorial() function accepts one argument and keeps calling itself by reducing value by one till it reaches 1.Exampledef factorial(x):     if x==1:         return 1     else:         return x*factorial(x-1) f=factorial(5) print ("factorial of 5 is ",f)OutputThe result isfactorial of 5 is  120

How can I write in order with for loop or while loop?

Arnab Chakraborty
Updated on 20-Jun-2020 15:34:17

157 Views

Example#include #include void main() {    int i,j,a=0,b=1,n;    clrscr();    printf("****************OUTPUT*****************");    printf("enter the value of n : ");    scanf("%d",&n);    printf(" the required order is: " );    for(i=1;i

How to use JavaScript to create client-side image map?

Abhishek
Updated on 25-Nov-2022 07:16:43

1K+ Views

In this tutorial, we will see how we can create a client-side image map using JavaScript. We use JavaScript to create a client-side image map. Client−side image maps are enabled by the usemap attribute for the tag and defined by special and extension tags. The image that is going to form the map is inserted into the page using the element as normal, except that it carries an extra attribute called usemap. The value of the usemap attribute is the value of the name attribute on the element, which you are about to meet, preceded ... Read More

How to print the Fibonacci Sequence using Python?

Jayashree
Updated on 21-Feb-2020 12:25:51

567 Views

Fibonacci series contains numbers where each number is sum of previous two numbers. This type of series is generated using looping statement.Examplex=0 y=1 fibo=0 while fibo

How to generate armstrong numbers in Python?

Jayashree
Updated on 21-Feb-2020 12:26:50

1K+ Views

Any three digit number is called an Armstrong number of sum of cube of its digits equals the number itself. In order to check if a number satisfies this condition, each digit from it is successively separated from right and its cube is cumulatively added. In the end if the sum is found to be equal to original number, it is called Armstrong number.ExampleFollowing Python code prints all armstrong numbers between 100 to 999for num in range(100, 1000):   temp=num   sum=0   while temp>0:     digit=temp%10     sum=sum+digit**3     temp=temp//10   if sum==num:     ... Read More

How to find the greatest number in a list of numbers in Python?

Jayashree
Updated on 21-Feb-2020 12:27:17

174 Views

Python's built-in library function max() returns the largest number in an iterable or commaa separated list of numbers.>>> max(10,23,43,21) 43 >>> l1=[4,7,2,9,1] >>> max(l1) 9

How to do Python math at command line?

Vikram Chiluka
Updated on 28-Oct-2022 11:29:37

1K+ Views

In this article, we will show you how to do python math at the command line. Python is an interpreter-based language. When you invoke the Python interpreter, (>>>) Python prompt appears. Any Python statement can be entered in front of it. As soon as you press ENTER, the statement is executed. Hence a mathematical expression using operators defined in Python will be evaluated at the command line. What are Operators? A symbol or function that represents an operation is called an operator. For instance, in mathematics, the addition operator is represented by the plus sign (+). While some of ... Read More

How to find sum a list of numbers in Python?

Jayashree
Updated on 21-Feb-2020 12:30:30

111 Views

Python's built-in function sum() returns sum of numbers in an iterable object such as list or tuple. It takes two arguments, initial value which is optional and 0 by default and iterable objectExample>>> l1=[10,20,30,40,50] >>> ttl=sum(l1) >>> ttl 150 >>> ttl=sum(range(10)) >>> ttl 45

Advertisements