INDEX
[Link] TITLE PAGE NO.
1 Grocery Billing System 2
2 Daily Task Remainder 3
3 Email Domain Checker 4
4 Patient Vital Sign Alert System 4
5 Password Validator With Retry 5
6 Rainfall Tracker 5
7 Credit Card Fraud Detection 6
8 Student Grades Processing System 7
9 Boxes Limit 8
10 Family Tree 8
11 Library Overdue Charges 9
12 Cinema Seat Checker 10
13 Student Sorting 11
14 Minimum Distance Route 12
15 E-Commerce Cart System 13
16 Fibonacci Stock Prediction 14
17 Expense Tracker 15
18 Voting System 15
19 Salary Slip Generator 16
1 of 17
1) Grocery Billing System
You own a grocery store and want to keep track of available items. Given a
tuple of available grocery items, check if a customer’s requested item is
available. If yes, calculate the bill based on quantity and unit price.
Code
store = []
n = int(input("How many items do you want to add in store: "))
for i in range(n):
print("Item", i + 1, "-")
item = input("Enter name of item: ")
quantity = int(input("Enter quantity: "))
price = int(input("Enter price of each item: "))
temp = [item, quantity, price]
[Link](temp)
store = tuple(store)
item = input("Enter item name to find in store: ")
quantity = int(input("Enter how many of those items you want: "))
found = False
for i in store:
if i[0] == item:
found = True
if i[1] >= quantity:
print("Total amount = ", quantity * i[2], "Rs")
break
else:
print("Not enough items in store")
if found == False:
print("The item is not available in store")
Output
2 of 17
2) Daily Task Remainder
You want to set a tuple of tasks and repeat your daily routine for a week.
Code
num = int(input("Enter how many tasks you want to daily: "))
t = []
for i in range(num):
print("Enter task ", i + 1, ": ", end = '')
tasks = input()
[Link](tasks)
t = tuple(t)
week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
'Sunday']
for i in range(7):
print("Day:", week[i], ", Do ->")
for j in range(len(t)):
print("Task ", j + 1, ": ", end = '')
print(t[j])
Output
3 of 17
3) Email Domain Checker
You are developing a form validation for a website. Check if a user’s email ends
with an allowed domain.
Code
n = int(input("Enter how many domains are to be allowed in your website: "))
domains = []
for i in range(n):
print("Domain", i + 1, ": ", end = '')
dom = input()
[Link](dom)
userEmail = input("Enter your email to validate in website: ")
parse = [Link]('@')
if parse[1] in domains: print("Valid")
else: print("Couldn't Validate”)
Output
4) Patient Vital Sign Alert System
Patient vitals alert system. Given a patient's heart rate & BP, generate alert
heart rate: normal(60-100) high(>100) low (<60), BP: check hypertensive
condition.
Code
hr = int(input("Enter patient's heartrate = "))
bp = int(input("Enter patient's blood pressure = "))
if (hr >= 60 and hr <= 100):
print("Normal Heartrate")
elif (hr > 100):
print("Heartrate is HIGH")
else:
print("Heartrate is LOW")
if (bp < 120):
print("Patient have a NORMAL Blood Pressure")
elif (bp >= 120 and bp < 130):
print("Patient have a elevated Blood Pressure")
elif (bp >= 130 and bp < 140):
print("Patient have a Hypertensive Condition")
else:
print("Patient have a Hypertensive crisis and need Medical Emergency")
4 of 17
Output
5) Password Validator With Retry
Password validation with retry. Enter password rules & verify if invalid, at least
8 characters, contains a number, contain an uppercase letter.
Code
while True:
password = input("Enter your Password: ")
if len(password) < 8:
print("Password must be at least 8 characters long, enter password again.")
continue
numCheck = False
upperCheck = False
for i in password:
if [Link]():
numCheck = True
if [Link]():
upperCheck = True
if not numCheck:
print("Password must contain a number, enter password again.")
continue
if not upperCheck:
print("Password must contain an uppercase letter, enter password again.")
continue
print("You have entered a valid Password!")
break
Output
6) Rainfall Tracker
RainFall Tracker for 12 months that-
● Takes rainfall inputs for 12 months
● Calculates total and average rainfall
● Displays the month with Highest and Lowest rainfall
5 of 17
Code
l = eval(input("Enter rainfall in meter(m) for 12 months: "))
l = list(l)
total, high, low = 0, -1, 9999
for i in l:
total += i
high = max(high, i)
low = min(low, i)
print("Total rainfall = ", total)
print("Average rainfall = ", total / 12)
print("Highest rainfall = ", high)
print("Lowest rainfall = ", low)
Output
7) Credit Card Fraud Detection
Credit Card Fraud Detection
Given a list of transcations:[3000, 75000, -2500 , 42000, 52000]
Credit a function that Flag:
● All transactions over 50,000
● Any Transaction with Negative amount(Fraudulent Reversal)
Code
def fraudDetection(transactions):
print("Transations over 50,000: ")
for i in transactions:
if i > 50000:
print(i, end = ", ")
print()
print("Negetive Transactions: ")
for i in transactions:
if i < 0:
print(i, end = ",")
print()
transactions = [3000, 75000, -2500, 42000, 52000]
fraudDetection(transactions)
Output
6 of 17
8) Student Grades Processing System
Student Grades Processing System
List of Marks: [92, 85, 76, 59, 66]
Write a function to:
● Assign Grades(A,B,C,D,F) based on Marks
● Return a dictionary with student index & grade.
Grading Scheme:
[A: 90+,B: 80-89, C: 70-79, D:60-69: F: < 60 ]
Code
def fraudDetection(transactions):
print("Transations over 50,000: ")
for i in transactions:
if i > 50000:
print(i, end = ", ")
print()
print("Negetive Transactions: ")
for i in transactions:
if i < 0:
print(i, end = ",")
print()
transactions = [3000, 75000, -2500, 42000, 52000]
fraudDetection(transactions)
def gradingSystem(marks):
dict = {}
for i in range(len(marks)):
if marks[i] >= 90:
dict[i] = 'A'
elif marks[i] >= 80 and marks[i] < 90:
dict[i] = 'B'
elif marks[i] >= 70 and marks[i] < 80:
dict[i] = 'C'
elif marks[i] >= 60 and marks[i] < 70:
dict[i] = 'D'
else: dict[i] = 'F'
return dict
marks = [92, 85, 76, 59, 66]
dict = gradingSystem(marks)
print(dict)
Output
7 of 17
9) Boxes Limit
An e-commerce company packs orders into boxes. Each box can carry items up
to a certain weight limit. Given a list of item weights, group them into tuples
representing each box. If an item exceeds the box limit, skip it.
Code
def pack_items_into_boxes(items, box_limit):
boxes = []
current_box = []
current_weight = 0
for item in items:
if item > box_limit:
continue
if current_weight + item <= box_limit:
current_box.append(item)
current_weight += item
else:
[Link](tuple(current_box))
current_box = [item]
current_weight = item
if current_box:
[Link](tuple(current_box))
return boxes
box_limit = int(input("Enter box limit: "))
items = eval(input("Enter weights of items: "))
items = list(items)
result = pack_items_into_boxes(items, box_limit)
print(result)
Output
10) Family Tree
Represent a family tree as a dictionary where keys are people and values are
tuples of their parents. Write a recursive function to find all ancestors of a
given person.
Code
def recur(family_tree, person):
if person in family_tree:
parents = family_tree[person]
print("Person:", person, "Parents:", parents)
for parent in parents:
if parent in family_tree:
recur(family_tree, parent)
8 of 17
else:
print("Person:", person, "Parents: None")
family_tree = {
"Joy": ("Papa", "Mummy"),
"Papa": ("Grandfather1", "Grandmother1"),
"Mummy": ("Grandfather2", "Grandmother2"),
"Grandfather1": ("Greatgrandfather1", "Greatgrandmother1"),
"Grandmother1": ("Greatgrandfather2", "Greatgrandmother2"),
"Grandfather2": ("Greatgrandfather3", "Greatgrandmother3"),
"Grandmother2": ("Greatgrandfather4", "Greatgrandmother4")
}
recur(family_tree, "Joy")
Output
11) Library Overdue Charges
A library charges a daily fine for overdue books:
● First 5 days : 2/day
● Next 5 days : 5/day
● Beyond 10 days : 10/day
Write an iterative function to calculate the for each book, and a recursive
function to sum total fines for all overdue books.
Code
def recur(ind, books, n, total):
if ind == n:
return total
if books[ind] <= 5:
total += books[ind] * 2
elif books[ind] <= 10:
total += 5 * 2 + (books[ind] - 5) * 5
else:
total += 5 * 2 + 5 * 5 + (books[ind] - 10) * 10
return recur(ind + 1, books, n, total)
books = eval(input("Enter overdue days of books: "))
books = list(books)
ans = []
for days in books:
if days <= 5:
9 of 17
[Link](days * 2)
elif days <= 10:
sum = 5 * 2 + (days - 5) * 5
[Link](sum)
else:
sum = 5 * 2 + 5 * 5 + (days - 10) * 10
[Link](sum)
print("Individual Fines:", ans)
# recursion
print("Total Fine:", recur(0, books, len(books), 0))
Output
12) Cinema Seat Checker
A cinema has rows of seats represented as a list of tuples where each tuple
contains seat numbers already booked. Write:
An iterative function to check if a given seat is available
A recursive function to count the total number of booked seats in the cinema
Code
def recur(ind, rows, n, total):
if ind == n: return total
total += len(rows[ind])
return recur(ind + 1, rows, n, total)
n = int(input("Enter number of rows in cinema: "))
rows = []
for i in range(n):
t = eval(input(f"Enter seats in row {i + 1} that are already booked: "))
[Link](t)
avail = int(input("Enter seat number to check if its available: "))
flag = 0
for row in rows:
if avail in row:
flag = 1
print("Sorry seat is already booked")
break
if not flag: print("Yes seat is available")
# recursion
print("Total booked seats:", recur(0, rows, len(rows), 0))
10 of 17
Output
13) Student Sorting
Write a program to sort a list of student records (each record: name, roll,
marks) by marks (descending) and then by name (ascending) using ‘sorted()’
with a custom key.
Code
students = [
("Riya", 101, 85),
("Amit", 102, 92),
("Neha", 103, 85),
("Karan", 104, 92),
("Sneha", 105, 78)
]
def sort_key(student):
name = student[0]
roll = student[1]
marks = student[2]
return (-marks, name)
sorted_students = sorted(students, key=sort_key)
print("Sorted Student Records:")
for student in sorted_students:
print("Name:", student[0], "| Roll:", student[1], "| Marks:", student[2])
Output
11 of 17
14) Minimum Distance Route
You have to deliver packages to multiple locations in a city. The city is
represented as a list of tuples (location_name, distance) in km. Write:
A recursive function to find the minimum distance route(starting from the
first location and visiting all others exactly once).
An iterative function to calculate the total distance of a given route.
Code
city_locations = [
("A", 0),
("B", 10),
("C", 15),
("D", 20)
]
def find_min_route(current_index, remaining_locations, current_distance, min_route,
min_distance):
if not remaining_locations:
if current_distance < min_distance[0]:
min_distance[0] = current_distance
min_route[:] = current_index[:]
return
for i in range(len(remaining_locations)):
next_loc = remaining_locations[i]
next_distance = abs(city_locations[current_index[-1]][1] - city_locations[next_loc][1])
find_min_route(
current_index + [next_loc],
remaining_locations[:i] + remaining_locations[i+1:],
current_distance + next_distance,
min_route,
min_distance
)
def calculate_total_distance(route):
total_distance = 0
for i in range(len(route) - 1):
total_distance += abs(city_locations[route[i]][1] - city_locations[route[i + 1]][1])
return total_distance
start_index = 0
remaining = list(range(1, len(city_locations)))
min_route = []
min_distance = [float('inf')]
find_min_route([start_index], remaining, 0, min_route, min_distance)
print("Shortest Route (by indices):", min_route)
print("Shortest Route (by names):", [city_locations[i][0] for i in min_route])
12 of 17
print("Minimum Distance:", min_distance[0], "km")
example_route = [0, 2, 1, 3]
total = calculate_total_distance(example_route)
print("\nExample Route:", [city_locations[i][0] for i in example_route])
print("Total Distance:", total, "km")
Output
15) E-Commerce Cart System
E-commerce Cart System: Simulate a shopping cart where items are stored as
tuples (item, price, qty). Calculate total cost and apply discount if total > 500.
Code
def get_cart_total(cart):
print("--- Shopping Cart ---")
total = 0
for item, price, qty in cart:
total = total + (price * qty)
print(f"Total: ${total:.2f}")
if total > 500:
discount = total * 0.10
final_price = total - discount
print(f"10% discount applied: -${discount:.2f}")
print(f"Final Price: ${final_price:.2f}\n")
return final_price
else:
print("No discount.")
print(f"Final Price: ${total:.2f}\n")
return total
cart1 = [("Laptop", 1200.00, 1), ("Mouse", 25.50, 2)]
cart2 = [("PC", 2500.00, 1), ("Monitor", 400.00, 2)]
get_cart_total(cart1)
get_cart_total(cart2)
Output
16) Fibonacci Stock Prediction
13 of 17
Recursive Fibonacci Stock Prediction: Predict stock growth assuming Fibonacci
pattern for n days. Store results in a file.
Code
def fib(n):
if n in memo:
return memo[n]
if n <= 1:
return n
result = fib(n - 1) + fib(n - 2)
memo[n] = result
return result
def predict_stock(days, filename="stock_prediction.txt"):
print("\n--- Stock Prediction ---")
with open(filename, 'w') as f:
[Link]("Stock Prediction\n")
for day in range(1, days + 1):
predicted_value = fib(day)
[Link](f"Day {day}: Value = {predicted_value}\n")
print(f"Prediction saved to {filename}\n")
predict_stock(15)
Output
17) Expense Tracker
14 of 17
Expense Tracker: Provide a list of expenses per day, calculate monthly total
using recursion, and save reports.
Code
def total_expenses_recursive(expenses, i=0):
if i >= len(expenses):
return 0
return expenses[i] + total_expenses_recursive(expenses, i + 1)
def save_expenses(daily_expenses, filename="[Link]"):
print("--- Expense Tracker ---")
total = total_expenses_recursive(daily_expenses)
with open(filename, 'w') as f:
[Link]("Expense Report\n")
for i, expense in enumerate(daily_expenses):
[Link](f"Day {i+1}: ${expense:.2f}\n")
[Link](f"Total: ${total:.2f}\n")
print(f"Expense report saved to {filename}\n”)
expenses = [50.25, 30.00, 150.75, 22.50, 80.00]
save_expenses(expenses)
Output
18) Voting System
Tuple-based Voting System: Simulate voting system where votes are stored as
tuples (voterid, candidate). Ensure no duplicate voter IDs. Save final result to
file.
Code
def count_votes(votes, filename="[Link]"):
print("--- Voting System ---")
voted = set()
counts = {}
for voter_id, candidate in votes:
if voter_id not in voted:
[Link](voter_id)
counts[candidate] = [Link](candidate, 0) + 1
else:
15 of 17
print(f"Voter '{voter_id}' already voted. Ignoring.")
with open(filename, 'w') as f:
[Link]("Voting Results\n")
for candidate, count in [Link]():
[Link](f"{candidate}: {count} votes\n")
print(f"Results saved to {filename}\n")
votes_list = [
("voter1", "Candidate A"),
("voter2", "Candidate B"),
("voter3", "Candidate A"),
("voter1", "Candidate C"),
("voter4", "Candidate B"),
]
count_votes(votes_list)
Output
19) Salary Slip Generator
Employee Salary Slip Generator: Read employee details (name, hours worked,
hourly rate) from a file, calculate salary, and save slips to new files per
employee.
Code
def make_salary_slips(input_file="[Link]"):
print("--- Salary Slip Generator ---")
with open(input_file, 'w') as f:
[Link]("Alice,40,25.50\n")
[Link]("Bob,45,30.00\n")
[Link]("Charlie,38,22.75\n")
with open(input_file, 'r') as f:
for line in f:
name, hours, rate = [Link]().split(',')
salary = int(hours) * float(rate)
slip_filename = f"{name}_slip.txt"
with open(slip_filename, 'w') as slip_file:
slip_file.write(f"Salary Slip for {name}\n")
slip_file.write(f"Hours: {hours}\n")
slip_file.write(f"Rate: ${float(rate):.2f}\n")
slip_file.write(f"Total Salary: ${salary:.2f}\n")
print(f"Created slip for {name}")
make_salary_slips()
16 of 17
Output
17 of 17