PYTHON PROGRAM LIST
1. Write a python program to find the largest of three numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
2. Write a python program to find the factorial of a number.
num = int(input("enter a number"))
factorial = 1
if num < 0:
print(" factorial does not exist ")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
3. Write a python program to find the amstrong of a number.
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
4. Write a python program to accept the percentage of a student and display the grade using if-elif-
else statement.
perc=float(input("enter percentage of a student"))
if perc>85:
print('A')
elif perc>70 and perc <= 85:
print('B')
elif perc>60 and perc <= 70:
print('C')
elif perc>45 and perc <= 60:
print('D')
else:
print('E')
5. Write a python program to find the sum of all elements in a list.
lst=eval(input("enter the elements of list"))
sum=0
for i in lst:
sum=sum+i
print("The elements in list are: ",lst)
print("The sum is", sum)
6. Write a python program to find atleast one common element amongst the two inputted list.
list1=eval(input("enter the list"))
list2=eval(input("enter the list"))
print("The elements in list1 are:",list1)
print("The elements in list2 are:",list2)
for x in list1:
for y in list2:
if x==y:
print("the common element is",x)
7. Write a python program to calculate simple interest by inputting the value of principal amount
and rate from the user for a time period of 5 years.
principal=int(input("enter the value of principal:"))
rate=int(input("enter the annual rate of interest:"))
time=5
simple_int=(principal*rate*time)/100
amount=principal+simple_int
print("simple interest=Rs.",simple_int)
print("amount payable=Rs.",amount)
8. Write a python program to find the reverse of a number.
num = int(input("enter a number"))
rev = 0
while num != 0:
digit = num % 10
rev = rev * 10 + digit
num //= 10
print("Reversed Number: ", rev)
9. Write a python program to find the smallest and largest number in a list.
num=eval(input("enter the list"))
print(num)
smallest = num[0]
for val in num:
if val < smallest:
smallest = val
print("the smallest element is:",smallest)
print(smallest)
largest = num[0]
for val in num:
if val > largest:
largest = val
print("the largest element is:",largest)
print(largest)
10. Create a dictionary to store names of states and their capitals.
states=dict()
n=int(input("how many states are there"))
for i in range(n):
state=input("enter name of the state")
capital=input("enter name of the capital")
states[state]=capital
print("the created dictionary is", states)