Assignment 1: Student Gradebook System
Problem Statement
Create a Python program that manages students’ marks, calculates averages, and displays
performance reports.
The user should be able to:
Add students and their marks
View all records
Search for a student
Display results sorted by average marks
Step 1: Create an empty list
students = []
Step 2: Ask for number of students
n = int(input("Enter number of students: "))
Step 3: Loop for student input
for i in range(n):
Step 4: Input student name & marks
name = input("Enter student name: ")
marks = []
for j in range(3):
m = float(input("Enter mark: "))
[Link](m)
Step 5: Calculate average & store in list
avg = sum(marks) / len(marks)
[Link]({"name": name, "marks": marks, "average": avg})
Step 6: Show menu using loop
while True:
print("\n1. View Students\n2. Search\n3. Topper\n4. Sort by Average\n5.
Exit")
choice = input("Enter choice: ")
Step 7: Process options
if choice == "1":
for s in students:
print(s["name"], s["marks"], s["average"])
elif choice == "2":
name = input("Enter name to search: ")
found = False
for s in students:
if s["name"].lower() == [Link]():
print(s)
found = True
if not found:
print("Not found")
elif choice == "3":
topper = max(students, key=lambda x: x["average"])
class_avg = sum(s["average"] for s in students) / len(students)
print("Topper:", topper["name"], topper["average"])
print("Class Average:", class_avg)
elif choice == "4":
sorted_list = sorted(students, key=lambda x: x["average"],
reverse=True)
for s in sorted_list:
print(s["name"], s["average"])
elif choice == "5":
print("Goodbye")
break
else:
print("Invalid input")
Assignment 2: Shopping Cart System
Problem Statement
Design a text-based shopping cart where users can add, remove, and view products with prices
and quantities.
At checkout, display total cost and allow discount codes.
Algorithm Steps with Code Writing Sections
Step 1: Create product list (dictionary) and empty cart
Logic:
Create a dictionary with product names as keys and prices as values
Create an empty dictionary cart to store selected items
# Write code here
Step 2: Start while loop menu
Logic:
Run an infinite while True loop
Show menu options to the user
Take user input choice
# Write code here
Step 3: Show products option
Logic:
If user selects option 1
Loop through products dictionary
Print each product and its price
# Write code here
Step 4: Add item to cart
Logic:
If user selects 2
Ask for item name
Check if item exists in products dictionary
Ask for quantity
If item already in cart → increase quantity
Else → add item to cart with price & qty
If item not found in products → show error message
# Write code here
Step 5: Remove item from cart
Logic:
If user selects 3
Ask for item name to remove
If item exists in cart
o Ask for quantity to remove
o If removing full quantity → delete item from cart
o Else → reduce quantity
Else → show “Item not in cart”
# Write code here
Step 6: Display cart and total
Logic:
If user selects 4
Loop through cart items
Multiply price × quantity to get cost
Add all costs to total
Print item, quantity, and subtotal
Print total amount
# Write code here
Step 7: Checkout and exit
Logic:
If user selects 5
Calculate total bill
Ask for coupon code
If code is SAVE10, apply 10% discount
Show final bill
If user selects 6, exit loop
# Write code here