Click on the program to view the source code
Program 1. Write Python program to find sum of two numbers.
a = int ( input ( " Enter first number : " ) )
b = int ( input ( " Enter second number : " ) )
s = a + b
print ( " Sum of two numbers is " , s )
Program 2. Python program to find product of two numbers
a=int ( input (" Enter first number : " ) )
b=int (input ("Enter second number: "))
p=a*b
print( " Product of two numbers is : " , p)
Program 3. Write Python program to find average of two numbers.
a=int(input(" Enter first number :"))
b=int(input(" Enter second number : "))
s=(a+b)/2
print(" Average of two numbers is",s)
Program 4. Python program to find print x raise power to y
x = int ( input (" Enter value of x : " ) )
y = int (input ("Enter value of y : "))
ans=x ** y
print( " x raise to power y is : " , ans)
Program 5. Write Python program to find simple interest.
p=float(input(" Enter principal :"))
t=float(input(" Enter time :"))
r=float(input(" Enter rate :"))
si=(p*t*r)/100
print(" Simple Interst is",si)
Program 6. Python program to check whether the given number is even or odd
n=int(input("Enter a number:"))
if n%2==0:
print("Even")
else:
print("Odd")
Program 7. Python program to check whether the given number is divisible by 5 or not.
n=int ( input (" Enter a number : " ) )
r = n % 5
if r ==0:
print(n , " is divisible by 5")
else:
print( n , " is not divisible by 5 ")
Program 8. Python program to display the greater number among two numbers.
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
if a>b:
print(a,"is greater")
else:
print(b,"is greater")
Program 9. Python program to display the smaller number among two numbers.
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
if a<b:
print(a,"is smaller")
else:
print(b,"is smaller")
Program 10 . Python program to display whether the given number is positive, negative or zero
n = int ( input (" Enter a number : " ) )
if n > 0 :
print( n , " is positive ")
elif n < 0 :
print( n , " is negative ")
else:
print(n , " is zero")
Program 11. Python program to display the greatest number among three numbers.
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
if a>b and a>c:
print(a,"is greatest")
elif b>a and b>c:
print(b,"is greatest")
else:
print(c,"is greatest")
Program 12. Python program to display the smallest number among three numbers.
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
if a<b and a<c:
print(a,"is smallest")
elif b<a and b<c:
print(b,"is smallest")
else:
print(c,"is smallest")
Program 13. Python program to display middle number among three numbers
a = int ( input (" Enter first number : " ) )
b = int ( input (" Enter second number : " ) )
c = int ( input (" Enter third number : " ) )
if a>b and a<c or a<b and a>c :
print( a , " is middle number ")
elif b>a and b<c or b>a and b<c :
print( b , " is middle number ")
else:
print(c , "is middle number")
Program 14. Python program to display greatest number among four numbers
a = int ( input (" Enter first number : " ) )
b = int ( input (" Enter second number : " ) )
c = int ( input (" Enter third number : " ) )
d = int ( input (" Enter fourth number : " ) )
if a>b and a>c and a>d:
print( a , " is greatest number ")
elif b>a and b>c and b>d:
print( b , " is greatest number ")
elif c>a and c>b and c>d:
print(c , " is greatest number")
else:
print(d , "is greatest number")
Program 15. Python program to display smallest number among four numbers
a = int ( input (" Enter first number : " ) )
b = int ( input (" Enter second number : " ) )
c = int ( input (" Enter third number : " ) )
d = int ( input (" Enter fourth number : " ) )
if a<b and a<c and a<d:
print( a , " is smallest number ")
elif b < a and b<c and b<d:
print( b , " is smallest number ")
elif c<a and c<b and c<d:
print(c , " is smallest number")
else:
print(d , "is smallest number")
Program 16. Python program to display first five natural numbers using for loop
for i in range(1,6,1):
print(i)
Program 17. Python program to print 1,2,3,......10.
for i in range(1,11):
print(i)
Program 18. Python program to display first five natural numbers using while loop
i=1
while i<6:
print(i)
i+=1
Program 19. Python program to display first ten even numbers
a=2
for i in range(1,11):
print(a)
a=a+2
Program 20. Python program to display first twenty odd numbers
a=1
for i in range(1,21):
print(a , end=" ")
a=a+2
Program 21. Python program to find factorial of given number.
[Note: Factorial of any number is product of all lesser positive number. Example: 5 !=5*4*3*2*1=120 ]
[Note: Factorial of any number is product of all lesser positive number. Example: 5 !=5*4*3*2*1=120 ]
num = int ( input ( “ Enter a number : ” ) )
f = 1
for i in range ( num , 1 , -1 ) :
f = f * i
print ( “ Factorial of ” , num , “ is ”, f )
Program 22. Python program to display multiplication table of given number.
num = int ( input ( " Enter a number : " ) )
for i in range ( 1, 11 ) :
ans = num * i
print ( ans )
Program 23. Python program to find the sum of the first ten natural numbers.
sum=0
for i in range ( 1, 11 ) :
sum = sum + i
print ( " Sum of ten natural numbers is " , sum )
Program 24. Python program to print the factors of a given number.
num = int ( input ( “ Enter a number : ” ) )
for i in range(1,num+1):
if num % i == 0:
print (i)
Program 25. Python program to find the sum of the digits of an entered number.
num = int ( input ( " Enter a number : " ) )
sum = 0
while num>0:
r = num % 10
sum = sum + r
num = num // 10
print (" Sum of digits is " , sum)
Program 26. Python program to reverse a given number.
num = int ( input ( " Enter a number : " ) )
rev = 0
while num>0:
r = num % 10
rev = rev * 10 + r
num = num // 10
print (" Reverse of given number is " , rev)
Program 27. Python to test whether the supplied number is Palindrome number or not.
Hint: A word, phrase, or sequence that reads the same backwards as forwards is called Palindrome. Example : 121 , 101 etc
Hint: A word, phrase, or sequence that reads the same backwards as forwards is called Palindrome. Example : 121 , 101 etc
n = int ( input ( " Enter a number : " ) )
num=n
rev = 0
while n>0:
r = n % 10
rev = rev*10 + r
n = n // 10
if num==rev:
print( " Palindrome number ")
else:
print(" Not Palindrome number ")
Program 28. Python program to check whether the given number is Armstrong or not.
An Armstrong number is a number which equal to the sum of the cubes of its individual digits. For example: 153 is an Armstrong number as 153=(1)3+(5)3+(3)3=1+125+27=153
An Armstrong number is a number which equal to the sum of the cubes of its individual digits. For example: 153 is an Armstrong number as 153=(1)3+(5)3+(3)3=1+125+27=153
n = int ( input ( " Enter a number : " ) )
num=n
arm = 0
while n>0:
r = n % 10
arm = arm + r**3
n = n // 10
if num==arm:
print( " Armstrong number ")
else:
print(" Not Armstrong number ")
Program 29. Python program to display the series: 0, 1, 1, 2, 3, ... up to the 10th term(Fibonacci Series)
An integer in the infinite sequence 0,1, 1, 2, 3, 5, 8, 13, ..... of which the first two terms are 0 and 1 and each succeeding term is the sum of the two immediately preceding is called Fibonacci Series.
An integer in the infinite sequence 0,1, 1, 2, 3, 5, 8, 13, ..... of which the first two terms are 0 and 1 and each succeeding term is the sum of the two immediately preceding is called Fibonacci Series.
a=0
b=1
for i in range(1,11,1):
print (a , end=" ")
c=a+b
a=b
b=c
Program 30. Python program to display 7,22,11,34,17,..... up to 10th terms(Hailstone Series)
Start with any integer value greater than 0, say x. If x is even, then the next value in the series is x/2; if x is odd, then the next value in the series is 3x + 1. This type of series is called Hailstone series
Start with any integer value greater than 0, say x. If x is even, then the next value in the series is x/2; if x is odd, then the next value in the series is 3x + 1. This type of series is called Hailstone series
a=7
for i in range(1,11,1):
print (a , end=" ")
if a%2==0:
a=a//2
else:
a=3*a+1
Program 31. Python program to continuously add numbers entered by the user. Stop taking input when the sum exceeds 50.
total_sum = 0
while total_sum <= 50 :
num = int(input("Enter a number to add: "))
total_sum = total_sum + num
print("Current sum:", total_sum)
print("Loop stopped. Sum exceeded 50.")
Program 32. Python program to print numbers from 1 to 20, but skip multiples of 3 using continue.
for i in range(1, 21):
if i % 3 == 0:
continue
print ( i, end = " ")
Program 33. Python program to input a number and check whether it is prime or not .
num = int ( input ( " Enter a number : " ) )
c = 0
for i in range(1, num + 1):
if num % i == 0:
c += 1
if c == 2:
print( num , " is prime" )
else:
print( num , " is not prime" )
Program 34. Python program to print prime numbers between 1 to 100.
for num in range(1,101):
c = 0
for i in range(1, num + 1):
if num % i == 0:
c += 1
if c == 2:
print( num , end = " " )
Program 35. Python program that has given a list of numbers, find the first prime number using a loop. If a prime is found, break the loop. numbers = [10, 15, 16, 17, 20]
numbers = [10, 15, 16, 17, 20]
for num in numbers:
c = 0
for i in range(1, num + 1):
if num % i == 0:
c += 1
if c == 2:
print("First prime number is:", num)
break
Program 36. Python program to nested loop to print the multiplication table from 1 to 5.
for i in range(1,6):
for j in range(1,11):
print(i*j , end = " ")
print()
Program 37. Python program to create a list of 10 integers and print the list.
numbers = [ ]
for i in range( 1 , 11 ):
print("Enter integer", i , end=": ")
num = int ( input ( ) )
numbers.append ( num )
print ( numbers )
Program 38. Python program that takes 5 numbers as input from the user and stores them in a list, then prints the list and its sum.
numbers = [ ]
for i in range(1, 6):
print("Enter integer", i , end=": ")
num=int ( input ( ) )
numbers.append(num)
total_sum = sum(numbers)
print("The list of numbers is :", numbers)
print("The sum of the numbers is :", total_sum)
Program 39. Python program that takes ten numbers from the user and stores them in a list. Separate even and odd numbers into two different lists, then print both lists.
all_numbers = [ ]
even_numbers = [ ]
odd_numbers = [ ]
for i in range(1,11):
print("Enter integer", i , end=": ")
num = int ( input ( ) )
all_numbers.append(num)
for num in all_numbers:
if num % 2 == 0:
even_numbers.append(num)
else:
odd_numbers.append(num)
print("Even numbers:", even_numbers)
print("Odd numbers:", odd_numbers)
Program 40. Python program to input any 10 integers in a list and display the reverse of given list.
integers = [ ]
for i in range(10):
print("Enter integer", i +1 , end=": ")
num = int ( input ( ) )
integers.append(num)
integers.reverse( )
print(" Reversed List is :", integers)
Program 41. Python program to create a list with 10 elements and find the greatest and smallest numbers in the list.
integers = [ ]
for i in range(10):
print("Enter integer", i +1 , end=": ")
num = int ( input ( ) )
integers.append(num)
g=max(integers)
s=min(integers)
print(" Greatest number is : " , g )
print( " Smallest number is : " , s )
Program 42. Python program to append a new element to the end of a list and print the updated list.
Program 43. Python program to print the length of a list.
Program 44. Python program to check if a given element exists in the list.
Program 45. Python program to count the number of times a specific element appears in the list.
Program 46. Python program to find the index of a specific element in a list.
Program 47.
Program 48.
Program 49.
Program 50.
Program 51.
Program 52.
Program 53.
Program 54.
Program 55.
Program 56.
Program 57.
Program 58.
Program 59.
Program 60.