Program 1A
Simple arithmetic operations as per user’s wish
Problem Statement:
Write a program to carryout all arithmetic operations namely,
addition, subtraction, multiplication, division, remainder, raised
to etc. on two numbers as per user’s choice.
Logic :
1. Start the program.
2. Ask the user to enter the first number.
3. Ask the user to enter the second number.
4. Display a menu of operations:
• Addition
• Subtraction
• Multiplication
• Division
• Remainder
• Power
5. Ask the user to choose an operation.
6. Use if–elif statements to perform the selected operation.
7. Display the result.
8. End the program.
Page no: 1
Code :
#Title: Simple arithmetic operations as per user’s wish.
#Name: Apurv P. Kadam
#Roll no: 8
#Div: B
#Branch: AIML
print(" • To perform algebraic calculation:\n")
a = float(input(" Enter any two integers:\n\t a = "))
b = float(input("\t b = "))
print("\n Which calculation you want to perform:")
print(" Press 1 for Addition.\n Press 2 for Substraction.")
print(" Press 3 for Multiplication.\n Press 4 for Division.")
print(" Press 5 for Remainder.\n Press 6 for Power.")
choice = int(input(" Your answer--> "))
if choice == 1 :
print(f"\n {a} + {b} = {a + b}")
elif choice == 2 :
print(f"\n {a} - {b} = {a - b}")
elif choice == 3 :
print(f"\n {a} × {b} = {a * b}")
elif choice == 4 :
if b == 0:
print(f"\n {a} ÷ {b} = Undefined")
else :
print(f"\n {a} ÷ {b} = {a / b}")
elif choice == 5 :
print(f"\n {a} % {b} = {a % b}")
elif choice == 6 :
print(f"\n {a}^{b} = {a ** b}")
else :
print("\n !!Error!!\n Invalid choice.")
Page no: 2
Output :
For addition :
For substraction :
For multiplication :
For division :
For remainder :
For Power :
Page no: 3
Program 1B
Area and perimeter of simple geometric shapes
as per user’s wish
Problem Statement :
Write a program to calculate area and perimeter of simple geometric
shapes like circle, triangle, square, rectangle, etc. as per user’s choice. First
ask the user about his/her choice about the geometric shape. Once user
selects the geometric shape, ask the user to provide the characteristic
dimensions of the selected geometric shape. Calculate area and
perimenter of the selected geometric shape and display it on screen.
Logic :
1) Start the program.
2) Display a menu of geometric shapes:
• Circle
• Rectangle
• Square
• Triangle
3) Ask the user to choose a shape.
4) Based on the selected shape:
5) Ask for required dimensions.
6) Calculate area and perimeter using formulas.
7) Display the area and perimeter.
8) End the program
Page no: 4
Code :
#Title: To calculate Area and perimeter of simple geometric shapes as per user’s wish.
#Name: Apurv P. Kadam
#Roll no: 8
#Div: B
#Branch: AIML
import math
print(" • To calculate area and perimeter of geometric figures:-")
print("\n Enter which shape's area and perimeter you want to calculate:")
print(" Press 1 for Circle.\n Press 2 for Rectangle.")
print(" Press 3 for Square.\n Press 4 for Triangle.")
choice = int(input(" Your answer--> "))
if choice == 1 :
print("\n For area and circumference of Circle:")
r = float(input("\n Enter the radius(in cm).\n\tRadius = "))
area = [Link] * r * r
peri = 2 * [Link] * r
print(f"\n Circle of radius = {r} has")
print(f" Area = {area:.2f}\n Circumference = {peri:.2f}")
elif choice == 2 :
print("\n For area and perimeter of Rectangle:")
l = float(input("\n Enter the length(in cm).\n\tLength = "))
w = float(input(" Enter the width(in cm).\n\tWidth = "))
area = l * w
peri = 2 * (l + w)
print(f"\n Rectangle of length = {l} and width = {w} has")
print(f" Area = {area:.2f}\n Perimeter = {peri:.2f}")
elif choice == 3 :
print("\n For area and perimeter of Square:")
s = float(input("\n Enter the side(in cm).\n\tSide = "))
area = s * s
peri = 4 * s
print(f"\n Square of side = {s} has")
print(f" Area = {area:.2f}\n Perimeter = {peri:.2f}")
elif choice == 4 :
print("\n For area and perimeter of Triangle:")
h = float(input("\n Enter the height(in cm).\n\tHeight = "))
b = float(input(" Enter the base(in cm).\n\tBase = "))
x = float(input(" Enter the side1(in cm).\n\tx = "))
y = float(input(" Enter the side2(in cm).\n\ty = "))
z = float(input(" Enter the side3(in cm).\n\tz = "))
area = 0.5 * b * h
peri = x + y + z
print(f"\n Triangle of height = {h}, base = {b},")
print(f" side1 = {x}, side2 = {y}, side3 = {z} has")
print(f" Area = {area:.2f}\n Perimeter = {peri:.2f}")
else :
print("\n\t !!Error!!\n Please press appropriate option.")
Page no: 5
Output :
For circle :
For rectangle :
For square :
For triangle :
Page no: 6
Program 1C
Simple Interest
Problem Statement :
Write a program to calculate simple interest that the user will get
at the end of maturity of his/her fixed deposit in a bank. Consider
following rates of interest for the corresponding tenure (period).
Rate of interest for Rate of interest for
Tenure (period)
Public Senior Citizen
7 days to 45 days 5.75 6.25
46 days to 179 days 6.25 6.75
180 days to 210 days 6.35 6.85
211 days to less than a year 6.40 6.90
1 year 6.40 6.90
Above 1 year to less than 455 days 6.40 6.90
456 days to less than 2 years 6.40 6.90
2 years to less than 3 years 6.50 7.00
3 years to less than 5 years 6.50 7.00
5 years to less than 10 years 6.50 7.00
Page no: 7
Logic :
1) Start
2) Input P, T, time unit, birth year
3) Find current year
4) Calculate age
5) If time unit = days → convert to years
6) Else if time unit = years → convert to days
7) If age ≥ 60 → senior citizen rates
8) Else if age ≥ 18 → public rates
9) Else → not eligible
10) Find rate based on tenure
11) Calculate SI = (P × R × T) / 100
12) Calculate Amount = P + SI
13) Display Age, Rate, SI, Amount
14) Stop
Page no: 8
Code :
#Title: To calculate simple interest.
#Name: Apurv P. Kadam
#Roll no: 8
#Div: B
#Branch: AIML
from datetime import datetime
print(" • To calculate simple interest:-\n")
print(" Please answer the following questions:")
p = float(input(" 1) Enter principal amount: "))
t = float(input(" 2) Enter time period: "))
d_or_y = input(" 3) Enter time unit (days/years): ")
birth_year = int(input(" 4) Enter your birth year: "))
current_year = [Link]().year
age = current_year - birth_year
if d_or_y.lower() == "days":
days = t
time_years = t / 365
if age >= 60:
if 7 <= days <= 45:
rate = 6.25
elif 46 <= days <= 179:
rate = 6.75
elif 180 <= days <= 210:
rate = 6.85
elif 211 <= days < 365:
rate = 6.9
elif 365 <= days < 730:
rate = 6.9
elif 730 <= days < 1825:
rate = 7
else:
rate = 7
si = (p * rate * time_years) / 100
amount = p + si
print("\n --Here are your details--")
print(" Age:", age)
print(" Rate of Interest:", rate)
print(" Simple Interest:", si)
print(" Maturity Amount:", amount)
elif 18 <= age < 60:
if 7 <= days <= 45:
rate = 5.75
elif 46 <= days <= 179:
rate = 6.25
Page no: 9
elif 180 <= days <= 210:
rate = 6.35
elif 211 <= days < 365:
rate = 6.4
elif 365 <= days < 730:
rate = 6.4
elif 730 <= days < 1825:
rate = 6.5
else:
rate = 6.5
si = (p * rate * time_years) / 100
amount = p + si
print("\n --Here are your details--")
print(" Age:", age)
print(" Rate of Interest:", rate)
print(" Simple Interest:", si)
print(" Maturity Amount:", amount)
else:
print("\n Age:", age)
print(" Sorry, you need to be 18 years old or above for a bank account.")
elif d_or_y.lower() == "years":
days = t * 365
time_years = t
if age >= 60:
if 7 <= days <= 45:
rate = 6.25
elif 46 <= days <= 179:
rate = 6.75
elif 180 <= days <= 210:
rate = 6.85
elif 211 <= days < 365:
rate = 6.9
elif 365 <= days < 730:
rate = 6.9
elif 730 <= days < 1825:
rate = 7
else:
rate = 7
si = (p * rate * time_years) / 100
amount = p + si
print("\n --Here are your details--")
print(" Age:", age)
print(" Rate of Interest:", rate)
print(" Simple Interest:", si)
print(" Maturity Amount:", amount)
elif 18 <= age < 60:
if 7 <= days <= 45:
rate = 5.75
elif 46 <= days <= 179:
Page no: 10
rate = 6.25
elif 180 <= days <= 210:
rate = 6.35
elif 211 <= days < 365:
rate = 6.4
elif 365 <= days < 730:
rate = 6.4
elif 730 <= days < 1825:
rate = 6.5
else:
rate = 6.5
si = (p * rate * time_years) / 100
amount = p + si
print("\n --Here are your details--")
print(" Age:", age)
print(" Rate of Interest:", rate)
print(" Simple Interest:", si)
print(" Maturity Amount:", amount)
else:
print("\n Age:", age)
print(" Sorry, you need to be 18 years old or above for a bank account.")
else:
print("\t!!ERROR!!\n!!Enter only days or years!!")
Output :
Page no: 11
Program 1D
Age Calculator
Problem Statement :
Write a program to determine age of a person in days till today. Later
convert it in to years, months and days. Take today’s date and date of
birth of a user in dd/mm/yyyy form as an input.
E.g. if the date of birth of a user is 18/02/1993 and today’s date is
12/03/2026 then the code should display following output :
The age of user is 12075 days.
The age of user is 33 years 0 months 22 days.
Logic :
1) Start the program.
2) Import datetime module.
3) Ask the user to enter Date of Birth in DD/MM/YYYY format.
4) Convert the input string into a date object using strptime().
5) Get the current date using [Link]().
6) Find the difference between today and date of birth.
7) Convert the difference into total number of days.
8) Calculate:
• Years = current year − birth year
• Months = current month − birth month
• Days = current day − birth day
9) If days become negative:
• Reduce months by 1
• Add 30 to days
10) If months become negative:
• Reduce years by 1
• Add 12 to months
11) Print:
• Age in total days
• Age in years, months, and days
12) End the program.
Page no: 12
Code :
#Title: To calculate age of the user.
#Name: Apurv P. Kadam
#Roll no: 8
#Div: B
#Branch: AIML
from datetime import datetime
print(" • To calculate age of the user:-\n")
dob_input = input(" Enter Date of Birth (DD/MM/YYYY): ")
dob = [Link](dob_input, "%d/%m/%Y")
today = [Link]()
difference = today - dob
total_days = [Link]
years = [Link] - [Link]
months = [Link] - [Link]
days = [Link] - [Link]
if days < 0:
months -= 1
days += 30
if months < 0:
years -= 1
months += 12
print("\n\t ~~Result~~")
print(f" The age of user (in days) is {total_days} days.")
print(f" The age of user is {years}years {months}months {days}days.")
Output :
Page no: 13
Program 1E
Salary of an Employee
Problem Statement :
Write a program to determine monthly salary of an employee. Salary
of an employee is composed of Basic Pay (BP), Dearness Allowance
(DA), House Rent Allowance (HRA), Travelling Allowance (TA) and
Gross Deduction (GD).
Salary = BP + DA + HRA + TA - GD
Basic Pay is given as per the level, which is based on designation
of an employee. Following are the levels and starting Basic Pay.
Level 1 2 3 4 5 6 7 8 9
BP(₹) 18,000 19,900 21,700 25,500 29,200 35,400 44,900 47,600 53,100
An increment of 3% of BP in BP is given is given every year to an
employee.
Dearness Allowance is based on inflation. Consider DA as 38% of
BP of an employee.
House Rent Allowance is based on the type of city in which
company is located. Following is HRA for different cities.
Type of city HRA
Tier 1 city (Mumbai, Pune, etc.) 30% of BP
Tier 2 city (Nagpur, Nashik, Virar, Vasai) 20% of BP
Tier 3 city (Satara, Sangli, Ratnagiri) 10% of BP
Page no: 14
Travelling Allowance is based on level of an employee and the
city in which company is located. The rates are as follows.
TA for Tier 1 and 2
Level TA for Tier 3 cities
cities
9 ₹ 7200 ₹ 3600
3 to 8 ₹ 3600 ₹ 1800
1 and 2 ₹ 1350 ₹ 900
Gross Deduction is composed of Professional Tax (₹ 200/-) and
Provident Fund (₹ 2000/-).
Logic :
1) Start the program.
2) Ask the user to enter:
• Employee level (1–9)
• City tier (1/2/3)
• Number of years worked
3) Assign Basic Pay (bp) based on employee level using if–elif
conditions.
4) Calculate Increment:
• Increment = Basic Pay × 3% × Years worked
5) Calculate Dearness Allowance (DA):
• DA = 38% of Basic Pay
6) Calculate House Rent Allowance (HRA) based on city tier:
• City 1 → 30% of BP
• City 2 → 20% of BP
• City 3 → 10% of BP
Page no: 15
Logic :
7) Calculate Travelling Allowance (TA):
• If City Tier 3:
> evel 9 → 3600
> Level ≥ 3 → 1800
> Otherwise → 900
• Else (City Tier 1 or 2):
> Level 9 → 7200
> Level ≥ 3 → 3600
> Otherwise → 1350
8) Set Gross Deduction (GD) = 2200
9) Calculate Total Salary:
• Salary = BP + Increment + DA + HRA + TA − GD
10) Display:
• Basic Pay
• DA
• HRA
• TA
• Gross Deduction
• Monthly Salary
11) End the program.
Page no: 16
Code :
#Title: To calculate salary of an employee.
#Name: Apurv P. Kadam
#Roll no: 8
#Div: B
#Branch: AIML
print(" • To calculate salary of an employee:-\n")
level = int(input(" Enter employee level (1-9): "))
city = int(input(" Enter city tier (1/2/3): "))
years = int(input(" Enter number of years worked: "))
if level == 1:
bp = 18000
elif level == 2:
bp = 19900
elif level == 3:
bp = 21700
elif level == 4:
bp = 25500
elif level == 5:
bp = 29200
elif level == 6:
bp = 35400
elif level == 7:
bp = 44900
elif level == 8:
bp = 47600
elif level == 9:
bp = 53100
increament = bp * 0.03 * years
da = 0.38 * bp
if city == 1:
hra = 0.3 * bp
elif city == 2:
hra = 0.2 * bp
else:
hra = 0.1 * bp
if city == 3:
if level == 9:
ta = 3600
elif level >= 3:
ta = 1800
else:
ta = 900
else:
if level == 9:
ta = 7200
elif level >= 3:
ta = 3600
Page no: 17
else:
ta = 1350
gd = 2200
salary = bp + increament + da + hra + ta - gd
print("\n --Here is the answer--")
print(" Basic Pay:", bp)
print(" Dearness Allowance:", da)
print(" House Rent Allowance:", hra)
print(" Travelling Allowance:", ta)
print(" Gross Deduction:", gd)
print(" Monthly Salary:", salary)
Output :
Page no: 18