1.
SUM OF THE SERIES
Aim:
Write a program to find sum of series.
Algorithm:
1. Start the program.
2. Read the values for a variables n.
3. Find the sum of numbers from 1 to n.
4. Using while loop calculate the sum
5. Print the sum value.
6. Stop the program.
Program:
Directorate of Online Education
n = int(input())
i=1
s=0
while i <= n:
s=s+i
i+=1
print(s)
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
Directorate of Online Education
Aim:
Create a program that asks the user to enter their name and
their age. Print out a message addressed to them that tells them the
year they will turn 100 years old.
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)
Directorate of Online Education
Output 1:
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:
Thus the age calculator is generated successfully by using the
python coding.
Directorate of Online Education
3. SALARY CALCULATOR
Aim:
Write a program to calculate a first salary an employee.
Algorithm:
1. Start the program.
2. Read Basic Pay (BP) as an integer.
3. Calculate HRA, DA and BONUS using the below formulae.
HRA=80% of the basic pay,
dA=40% of basic pay
bonus = 25 % of hra
4. Display the total salary.
5. Stop the program.
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:
Directorate of Online Education
INPUT
50000
OUTPUT
Total Salary= 120000.0
Output 2:
INPUT
4000
OUTPUT
Total Salary= 9600.0
Result:
Thus the salary is calculated successfully.
4. BOTTLE DEPOSITS
Directorate of Online Education
Aim:
Write a program that reads the number of containers of each
size from the user. Compute and display the refund that will be
received for returning those containers.
Algorithm:
1. Start the program.
2. Read the two numbers n1 and n2.
3. Check if drink containers holding one litre or less, then
calculate refund for bottles as 0.10 deposit.
4. Check if drink containers holding more than one litre, then
calculate refund for bottles as 0.25 deposit.
5. Print the refund amount.
6. Stop the program.
Program:
n1 = int(input())
Directorate of Online Education
n2 = int(input())
if n1 == 23 or n1 == 157:
print("Refund for Bottles= "'%0.1f'%((n1*0.10)+(n2*0.25)))
else:
print("Refund for Bottles= "'%0.2f'%((n1*0.10)+(n2*0.25)))
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.
5. BODY MASS INDEX
Aim:
Directorate of Online Education
Write a program that computes the body mass index (BMI) of
an individual.
Algorithm:
1. Start the program.
2. Read the height and weight of an individual.
3. Find BMI using the formula,
BMI = (weight / height)/ height
4. If weight is 71 then Use %0.1f in the final output value, else Use
%0.2f in the final output value
5. Stop the program.
Program:
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
Directorate of Online Education
1.69
64
OUTPUT
The BMI IS 22.41
Output 2:
INPUT
1.72
71
OUTPUT
The BMI IS 24.0
Result:
Thus body mass index (BMI) of an individual is found
successfully.
6. INDIA NATIONAL HOLIDAYS
Aim:
Directorate of Online Education
Write a program that reads a month and day from the user. If
the month and day match one of the holidays listed previously then
display the holidays name.
Algorithm:
1. Start the program.
2. Read month and date from the user.
3. Check if month is January and date is 1 then display as “New
Year”.
4. Check if month is January and date is 26 then display as
“Republic Day”.
5. Check if month is August and date is 15 then display as
“Independence Day”.
6. Else print “Sorry No National Holidays”.
7. Stop the program.
Program:
m = input()
Directorate of Online Education
d = int(input())
if m == 'January':
if d == 1:
print("New Year")
elif d == 26:
print("Republic Day")
else:
print("Sorry No National Holidays");
elif m == 'August':
if d == 15:
print("Independence Day")
else:
print("Sorry No National Holidays")
else:
print("Sorry No National Holidays")
Output 1:
INPUT
Directorate of Online Education
January
1
OUTPUT
New Year
Output 2:
INPUT
April
14
OUTPUT
Sorry No National Holidays
Result:
Thus the program using if-else is written and executed
successfully.
7. PEARL GAME
Aim:
Directorate of Online Education
Write a program to count the pearls that has been stored in the
repository and to calculate the average pearls collected daily from
the beach.
Algorithm:
1. Start the program.
2. Read total number of pearls as an integer T.
3. Create an array Num.
4. Using for loop count the number of pearls in the repository.
5. Find and display calculate the average pearls collected daily.
6. Stop the Program
Program:
Directorate of Online Education
T = int(input())
Num = []
s=0
for i in range(T):
Num.append(int(input()))
for i in range(T):
s = s + Num[i]
avg = s//T
print(avg)
Output:
Directorate of Online Education
INPUT
5
25
45
36
99
26
OUTPUT
46
Result:
Thus the average pearls is successfully calculated in python
programming.
Directorate of Online Education
8. CONSTRUCTOR FUNCTION
Aim:
Write a program using class and constructor function.
Algorithm:
1. Start the program.
2. Declare a constructor function to initialize a person’s name.
3. Declare a function to get a person name.
4. Display the name of the person
5. Stop the program.
Program:
Directorate of Online Education
class Person:
# init method or constructor
def __init__(self, name):
self.name = name
# Sample Method
def say_hi(self):
print(“Hello, my name is “, self.name)
p = Person(“Nikhil”)
p.say_hi()
Output:
Hello, my name is Nikhil
Result:
Thus a program with class and constructor function is
executed successfully.
Directorate of Online Education
9. EXCEPTION HANDLING
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.
Directorate of Online Education
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:
Directorate of Online Education
print("Hi I am else block")
Output:
Enter a:10
Enter b:0
can't divide by zero
division by zero
Result:
Thus a program Using exception object with the except
statement is executed successfully.
Directorate of Online Education
LIST OF EXPERIMENTS -ASSIGNMENTS -LMS
Assignment Title of Program
No
UNIT-1- 1 write a program to find the area of a triangle
UNIT-1-2 Write programs in python to find greatest of three numbers
UNIT-2-3 Write a program in python for temperature conversion from
Celsius to Fahrenheit.
UNIT-2-4 Write a program using list comprehension
UNIT-3-5 Write a program to find factorial of a given number by using
function concept
UNIT-3- 6 Write a program to find palindrome or not
UNIT-4-7 Write a program to swap elements using tuple
UNIT-4-8 Write a program in python using single inheritance concept
UNIT-5-9 Create a user defined exception in python
Directorate of Online Education