Python Lab Questions
Python Lab Questions
Aim:
Write a program to find sum of series.
Algorithm:
Program:
Output 1:
INPUT
18
OUTPUT
171
Output 2:
INPUT
100
OUTPUT
5050
Result:
Thus the python program to perform the sum of series is
written and executed successfully
2. AGE CALCULATOR
Algorithm:
1. Start the program.
2. Read the name and age of a person.
3. Find the difference between the given age and 100.
4. Print the sum of current year and the difference (step3).
5. Stop the program.
Program:
curr_Y = 2017
name = input()
age = int(input())
diff = 100 - age
print(name,"will be 100 years old in",curr_Y + diff)
INPUT
Ram
30
OUTPUT
Ram will be 100 years old in 2087
Output 2:
INPUT
Dhoni
35
OUTPUT
Dhoni will be 100 years old in 2082
Result:
Program:
BP = int(input())
HRA = (80*BP)/100
dA = (40*BP)/100
bonus = (25*HRA)/100
print("Total Salary=",BP+HRA+dA+bonus)
Output 1:
Output 2:
INPUT
4000
OUTPUT
Total Salary= 9600.0
Result:
4. BOTTLE DEPOSITS
Algorithm:
Program:
n1 = int(input())
Output 1:
INPUT
23
22
OUTPUT
Refund for Bottles= 7.8
Output 2:
INPUT
157
198
OUTPUT
Refund for Bottles= 65.2
Result:
Thus the bottle refund amount is calculated successfully.
Algorithm:
h = float(input())
w = int(input())
ans = (w/h)/h
if w == 71:
print("The BMI IS",'%0.1f'%ans)
else:
print("The BMI IS",'%0.2f'%ans)
Output 1:
INPUT
Output 2:
INPUT
1.72
71
OUTPUT
The BMI IS 24.0
Result:
Algorithm:
Program:
m = input()
Output 1:
INPUT
Output 2:
INPUT
April
14
OUTPUT
Sorry No National Holidays
Result:
7. PEARL GAME
Aim:
Algorithm:
Program:
Output:
Result:
Algorithm:
Program:
Output:
Hello, my name is Nikhil
Result:
Aim:
Write a program Using exception object with the except
statement
Algorithm:
1. Start the program.
2. Read numbers a and b.
3. Find a/b.
4. Display exception object with the except statement.
5. Stop the program.
try:
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = a/b
print("a/b = %d"%c)
# Using exception object with the except statement
except Exception as e:
print("can't divide by zero")
print(e)
else:
Output:
Enter a:10
Enter b:0
can't divide by zero
division by zero
Result: