Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Python fun programs

Uploaded by

mdas30001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Python fun programs

Uploaded by

mdas30001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

#Experiment No.

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:

Enter first number: 4


Enter second number: 2
Sum of 4 & 2 is: 6
Difference of 4 & 2 is: 2
Product of 4 & 2 is: 8
Division of 4 by 2 is: 2.0
Remainder of 4 % (modulo) by 2 is: 0
# Experiment No: 2

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!

Enter the age: 23


Eligible for voting!

Enter the age: 13


Not eligible for voting!
#Experiment No. 3

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!")

Remarks: Program executed successfully and output obtained!!!


OUTPUT:

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:

Enter a number: 1509


It is not an Armstrong number

Enter a number: 153


It is an Armstrong number
#Experiment No: 5

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:

Enter mark for Physics: 60


Enter mark for Chemistry: 70
Enter mark for Mathematics: 80
Enter mark for Computer Science: 100
Enter mark for English: 88

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

Enter your choice: 2

0
1
1
2
3
5

You might also like