Print multiplication table of 24, 50 and 29 using loop.
i=1whilei<=10:print24*ii=i+1
4.
Write an infinite loop. A inifinte loop never ends. Condition is always true.
whileTrue:print"INFINITE"
5.
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.- 4! = 1*2*3*4 = 24 3! = 3*2*1 = 6 2! = 2*1 = 2 Also, 1! = 1 0! = 1 Write a program to calculate factorial of a number.
Write a program to find greatest common divisor (GCD) or highest common factor (HCF) of given two numbers.
print"Enter first number"x=input()print"Enter second number"y=input()#x,y = 10, 20 means x = 10 y = 20whiley!=0:x,y=y,x%yprintx
7.
Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.
# Do it yourself# This type of example is discussed in tutorial
Level 2
1.
Calculate the sum of digits of a number given by user. E.g.- INUPT : 123 OUPUT : 6 INUPT : 12345 OUPUT : 15
print"Enter a number"number=input()summ=0#number%10 will give last digit of number#number = number/10 will give new number without that digit#we will stop when number will be smaller than 10whileTrue:r=number%10number=number/10summ=summ+rifnumber<10:summ=summ+numberbreakprintsumm
2.
A three digit number is called Armstrong number if sum of cube of its digit is equal to number itself. E.g.- 153 is an Armstrong number because (13)+(53)+(33) = 153. Write all Armstrong numbers between 100 to 500.
#Find seperate digits as done in previous question#then find the sum of cubes
3.
Write a program to print a number given by user but digits reversed. E.g.- INPUT : 123 OUTPUT : 321 INPUT : 12345 OUTPUT : 54321
4.
Write a program to find prime factor of a number. If a factor of a number is prime number then it is its prime factor.
This is not an efficent algorithm. You can also use sieve algorithm to find prime numbers. You can see this answer
print"Enter number"number=input()i=2whilei<=number:#Checking if prime or notj=2count=0whilej<=i:ifi%j==0:count=count+1j=j+1#if count > 1 then it is not prime#if prime and factor(number%i==0) then it is prime factorifcount<=1andnumber%i==0:printii=i+1
5.
Write a program to print all prime number in between 1 to 100.