Python fun programs
Python fun programs
AIM: To write a Python program to enter two numbers and perform arithmetic operations
(+,-,*,/).
PROGRAM:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Sum of", num1, "and", num2, "=", num1+num2)
print("Difference of", num1, "and", num2, "=", num1-num2)
print("Product of", num1, "and", num2, "=", num1*num2)
print("Division of", num1,"by",num2,"=",num1/num2)
RESULT:
Program executed successfully and output obtained.
OUTPUT:
AIM: To write a python program to enter the age and check whether eligible to vote or not.
PROGRAM:
age = int(input("Enter the age: "))
if age >= 18:
print("eligible for voting")
else:
print("not eligible for voting")
RESULT
Program executed successfully and output obtained !!!
OUTPUT:
Enter the age: 18
Eligible for voting!
Aim: To write a python program to find whether an entered number ("Enter a number:")
is perfect or not.
PROGRAM:
num = int(input("Enter a number:"))
sum = 0
for i in range(1, num):
if num % i == 0:
sum = sum + i
if sum == num:
print(num, "is a perfect number!")
else:
print(num, "is not a perfect number!")
Enter a number: 28
It is a perfect number!
Enter a number: 6
It is a perfect number!
Enter a number: 17
It is not a perfect number!
#Experiment No. 4
AIM :Write a python program to check whether the entered number is an Armstrong
number or not.
PROGRAM
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")
RESULT
Program executed successfully and output obtained!!
OUTPUT:
AIM :Write a python program to enter marks of 5 subjects and find out the grade of the
student.
PROGRAM
m1 = float(input("Enter mark for History: "))
m2 = float(input("Enter mark for Geography: "))
m3 = float(input("Enter mark for English: "))
m4 = float(input("Enter mark for Chemistry: "))
m5 = float(input("Enter mark for Computer science: "))
sum = m1+m2+m3+m4+m5
avg = sum/5
print(avg)
if avg >= 85:
print('Grade A')
elif avg >= 75 and avg < 85:
print('Grade B')
elif avg >= 65 and avg < 75:
print('Grade C')
else:
print('Grade D')
RESULT
Program was executed successfully and output is verified !!
OUTPUT:
Grade B
#Experiment No. 6
Aim: To write a menu driven program to find the factorial of a number and fibonacci series
upto 'n' terms.
PROGRAM:
print("1 : Factorial")
print("2 : Fibonacci")
ch = int(input("Enter your choice "))
num = int(input("Enter the number "))
if ch == 1:
fact = 1
for i in range(1, num+1):
fact = fact * i
print("Factorial =", fact)
elif ch == 2:
a=0
b=1
print(a)
print(b)
for i in range(2, num):
c=a+b
print(c)
a=b
b=c
else:
print(“Invalid choice”)
Remarks:
Program was executed successfully and output obtained!!
OUTPUT MENU
***********
1. Factorial of number
2. Fibonacci series
Enter your choice: 1
Factorial of 6 = 720
0
1
1
2
3
5