In the previous section we discussed the basics of Python Dictionaries. Now let us take a look at some real-life application Problems.
1. Student Result Processing System
Write a Python program to store a student’s name and marks in 5 subjects using variables. Calculate total, average and print Pass/Fail (Pass if average ≥ 40).
name = "John"
sub1 = 78
sub2 = 65
sub3 = 82
sub4 = 55
sub5 = 70
total = sub1 + sub2 + sub3 + sub4 + sub5
average = total / 5
print("Student Name:", name)
print("Total Marks:", total)
print("Average:", average)
if average >= 40:
print("Result: Pass")
else:
print("Result: Fail")
# Student Name: John
# Total Marks: 350
# Average: 70.0
# Result: Pass
2. Online Shopping Bill Calculator
Write a Python program to store product name, price, and quantity. Calculate total cost and apply 10% discount if total > ₹5000.
product = "Laptop Bag"
price = 1200
quantity = 5
total = price * quantity
discount = 0
if total > 5000:
discount = total * 0.10
final_amount = total - discount
print("Product:", product)
print("Total:", total)
print("Discount:", discount)
print("Final Amount:", final_amount)
# Product: Laptop Bag
# Total: 6000
# Discount: 600.0
# Final Amount: 5400.0
3. Bank Account Balance Update
Create variables to store the account holder’s name and balance. Perform deposit and withdrawal, then display the final balance.
name = "Amit"
balance = 10000
deposit = 3000
withdraw = 2500
balance = balance + deposit
balance = balance - withdraw
print("Account Holder:", name)
print("Final Balance:", balance)
# Account Holder: Amit
# Final Balance: 10500
4. Temperature Conversion
Write a Python program to store temperature in Celsius and convert it into Fahrenheit and Kelvin.
celsius = 30
fahrenheit = (celsius * 9/5) + 32
kelvin = celsius + 273.15
print("Celsius:", celsius)
print("Fahrenheit:", fahrenheit)
print("Kelvin:", kelvin)
# Celsius: 30
# Fahrenheit: 86.0
# Kelvin: 303.15
5. Employee Salary Calculator
Store employee’s basic salary. Calculate:
HRA = 20%
DA = 10%
Tax = 5% of gross
Find net salary.
employee = "Ronnie"
basic_salary = 40000
hra = basic_salary * 0.20
da = basic_salary * 0.10
gross_salary = basic_salary + hra + da
tax = gross_salary * 0.05
net_salary = gross_salary - tax
print("Employee:", employee)
print("Gross Salary:", gross_salary)
print("Tax:", tax)
print("Net Salary:", net_salary)
# Employee: Ronnie
# Gross Salary: 52000.0
# Tax: 2600.0
# Net Salary: 49400.0
6. Fuel Efficiency Tracker
Store distance travelled and fuel used. Calculate mileage and check if it is good (>15 km/l).
distance = 300 # in km
fuel = 18 # in litres
mileage = distance / fuel
print("Mileage:", mileage, "km/l")
if mileage > 15:
print("Fuel Efficiency is Good")
else:
print("Fuel Efficiency is Poor")
# Mileage: 16.666666666666668 km/l
# Fuel Efficiency is Good
7. Movie Ticket Booking System
Store movie name, ticket price, and number of tickets. Add ₹50 convenience fee and calculate the total bill.
movie = "Avengers"
ticket_price = 200
tickets = 4
total_cost = ticket_price * tickets
convenience_fee = 50
final_bill = total_cost + convenience_fee
print("Movie:", movie)
print("Ticket Cost:", total_cost)
print("Convenience Fee:", convenience_fee)
print("Final Bill:", final_bill)
# Movie: Avengers
# Ticket Cost: 800
# Convenience Fee: 50
# Final Bill: 850
8. Simple Interest Calculator
Store principal, rate, and time to calculate simple interest.
principal = 10000
rate = 8
time = 3
simple_interest = (principal * rate * time) / 100
print("Simple Interest:", simple_interest)
# Simple Interest: 2400.0