Found 27104 Articles for Server Side Programming

How to Find Factorial of Number Using Recursion in Python?

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

674 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

153 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

562 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

978 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

173 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

110 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

How to extract numbers from a string using Python?

Jayashree
Updated on 23-Jun-2020 06:13:54

484 Views

To extract each digit from a string −>>> str1='a34e 345 bcd 5he 78 xyz' >>> for s in str1: if s.isdigit():print (s) 3 4 3 4 5 5 7 8To extract only integers from a string in which words are separated by space character −>>> str1='h3110 23 cat 444.4 rabbit 11 2 dog' >>> for s in str1.split(): if s.isdigit(): print ((s)) 23 11 2

How to know Maximum and Minimum values for ints in Python?

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

68 Views

Python's core library has two built-in functions max() and min() respectively to find maximum and minimum number from a sequence of numbers in the form of list or tuple object.example>>> max(23,21,45,43) 45 >>> l1=[20,50,40,30] >>> max(l1) 50 >>> t1=(30,50,20,40) >>> max(t1) 50 >>> min(l1) 20 >>> min(t1) 20 >>> min(23,21,45,43) 21

Advertisements