Week 10 Assignments
Variant 1: The University Grade Analyzer
You are working for the University Registrar. You have been given a raw string of exam results from various professors. The data is messy and combined into one long list.
Your goal is to organize the data by Subject and calculate the Average Score for each subject to see which courses are too hard or too easy.
Requirements:
- Create a function
parse_grades(raw_data):- Input: A list of strings. Format:
"StudentName,Subject,Score". - Logic: Loop through the list, split the strings, and build a dictionary where:
- Key: Subject Name (String)
- Value: A List of all scores (Integers) for that subject.
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
print_averages(grade_dict):- Input: The dictionary created in step 1.
- Logic: Loop through the dictionary. For each subject, calculate the Average of the scores in the list.
- Output: Print the Subject and the Average (formatted to 2 decimal places).
Testing Inputs (Copy this into your code):
raw_data = [
"Alice,Math,85",
"Bob,Physics,70",
"Charlie,Math,90",
"David,Chemistry,60",
"Eve,Physics,88",
"Frank,Math,75",
"Grace,Chemistry,82",
"Heidi,Physics,95"
]
Expected Output:
Math Average: 83.33
Physics Average: 84.33
Chemistry Average: 71.00
Variant 2: The Sales Commission Tracker
You are building a payroll system for a retail store. Salespeople submit their sales log as raw text. You need to calculate the Total Sales for each employee to determine who is the “Top Performer”.
Requirements:
- Create a function
build_sales_log(sales_list):- Input: A list of strings. Format:
"EmployeeID|ItemName|Price". - Logic: Loop through the list, clean the data, and build a dictionary where:
- Key: EmployeeID (String)
- Value: A running Total Sum (Float) of their sales. (Note: Unlike Variant 1, you are summing immediately, not storing a list).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
find_top_performer(sales_dict):- Input: The dictionary created in step 1.
- Logic: Loop through the dictionary to find which EmployeeID has the highest Total Sales.
- Output: Print the EmployeeID and Amount of the winner.
Testing Inputs (Copy this into your code):
sales_list = [
"E101|Laptop|1200.00",
"E102|Mouse|25.50",
"E101|Monitor|300.00",
"E103|Headphones|150.00",
"E102|Keyboard|50.00",
"E103|Laptop|1000.00",
"E101|Mousepad|15.00"
]
Expected Output:
Sales Report:
E101: $1515.00
E102: $75.50
E103: $1150.00
--------------------
Top Performer is E101 with $1515.00
Variant 3: The Server Log Error Filter
You are a Junior System Administrator. Your server produces a messy log of access attempts. You need to identify which IP Addresses are generating too many Error codes (specifically code 404 or 500).
Requirements:
- Create a function
analyze_logs(log_entries):- Input: A list of strings. Format:
"IP_Address - StatusCode". - Logic: Loop through the list. You only care about entries where the Status Code is “404” or “500”. Ignore “200” (Success).
- Build a dictionary where:
- Key: IP Address (String)
- Value: A Count (Integer) of how many errors they caused.
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
flag_suspicious_ips(error_dict):- Input: The dictionary created in step 1.
- Logic: Loop through the dictionary. If an IP address has 3 or more errors, print a warning message.
Testing Inputs (Copy this into your code):
log_entries = [
"192.168.1.1 - 200",
"10.0.0.5 - 404",
"192.168.1.1 - 200",
"10.0.0.5 - 500",
"172.16.0.1 - 404",
"10.0.0.5 - 404",
"192.168.1.1 - 500",
"10.0.0.5 - 404"
]
Expected Output:
Error Counts:
10.0.0.5: 4
172.16.0.1: 1
192.168.1.1: 1
--------------------
SECURITY ALERT: 10.0.0.5 has 4 errors.
Variant 4: The Library Reading Challenge
You are a librarian managing a “Summer Reading Challenge”. Students submit the books they read in a specific format. You need to group the books by Genre and calculate the Total Pages read for each genre.
Requirements:
- Create a function
organize_books(reading_log):- Input: A list of strings. Format:
"Genre,BookTitle,PageCount". - Logic: Parse the list and build a dictionary:
- Key: Genre (String)
- Value: A List of Tuples, where each tuple is
(BookTitle, PageCount).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
print_genre_stats(library_dict):- Input: The dictionary from step 1.
- Logic: Loop through each genre. Sum the page counts of all books in that genre’s list.
- Output: Print the Genre and the Total Pages.
Testing Inputs (Copy this into your code):
reading_log = [
"Fantasy,The Hobbit,310",
"SciFi,Dune,412",
"Fantasy,Harry Potter,223",
"Mystery,Sherlock Holmes,300",
"SciFi,Ender's Game,324",
"Fantasy,The Alchemist,160"
]
Expected Output:
Fantasy: 693 pages total
SciFi: 736 pages total
Mystery: 300 pages total
Variant 5: The Logistics Weight Planner
You work for a shipping company. Packages are waiting at a central hub to be sent to different cities. You need to group the packages by Destination City and calculate the Total Weight for each city to decide which size truck to send.
Requirements:
- Create a function
group_packages(shipment_list):- Input: A list of strings. Format:
"City|PackageID|WeightKG". - Logic: Parse the list and build a dictionary:
- Key: City (String)
- Value: A List of Tuples, where each tuple is
(PackageID, WeightKG).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
calculate_truck_loads(shipping_dict):- Input: The dictionary from step 1.
- Logic: Loop through each city. Sum the weight of all packages in that city’s list.
- Output: Print the City and the Total Weight.
Testing Inputs (Copy this into your code):
shipment_list = [
"New York|Box101|50",
"Chicago|Box102|20",
"New York|Box103|30",
"Miami|Box104|15",
"Chicago|Box105|45",
"New York|Box106|10"
]
Expected Output:
New York: 90 kg total
Chicago: 65 kg total
Miami: 15 kg total
Variant 6: The Music Playlist Duration
You are a DJ organizing a setlist. You have a raw list of songs. You need to group the songs by Artist and calculate the Total Duration (in seconds) for each artist to ensure they get equal playing time.
Requirements:
- Create a function
categorize_music(track_list):- Input: A list of strings. Format:
"Artist-SongName-Seconds". - Logic: Parse the list and build a dictionary:
- Key: Artist (String)
- Value: A List of Tuples, where each tuple is
(SongName, Seconds).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
report_artist_time(music_dict):- Input: The dictionary from step 1.
- Logic: Loop through each artist. Sum the duration (seconds) of all songs in that artist’s list.
- Output: Print the Artist and the Total Duration.
Testing Inputs (Copy this into your code):
track_list = [
"Taylor Swift-Shake it Off-240",
"Queen-Bohemian Rhapsody-355",
"Taylor Swift-Love Story-235",
"Drake-God's Plan-200",
"Queen-We Will Rock You-120",
"Drake-Hotline Bling-260"
]
Expected Output:
Taylor Swift: 475 seconds total
Queen: 475 seconds total
Drake: 460 seconds total
Variant 7: The Charity Fundraiser
You are volunteering for a charity event. Donors have written down their pledges on a sign-up sheet. You need to group the donations by Cause (e.g., Animals, Environment) and calculate the Total Amount Raised for each cause.
Requirements:
- Create a function
process_donations(pledge_list):- Input: A list of strings. Format:
"DonorName,Cause,Amount". - Logic: Parse the list and build a dictionary:
- Key: Cause (String)
- Value: A List of Tuples, where each tuple is
(DonorName, Amount).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
print_fund_totals(charity_dict):- Input: The dictionary from step 1.
- Logic: Loop through each cause. Sum the amounts of all pledges in that cause’s list.
- Output: Print the Cause and the Total Amount.
Testing Inputs (Copy this into your code):
pledge_list = [
"Alice,Animals,50",
"Bob,Environment,100",
"Charlie,Animals,25",
"David,Education,200",
"Eve,Environment,50",
"Frank,Education,75"
]
Expected Output:
Animals: $75 total
Environment: $150 total
Education: $275 total
Variant 8: The Gamer's Loot Bag
You are coding an inventory system for an RPG video game. After a battle, the player collects a list of items. You need to organize these items by Item Type (e.g., Weapon, Potion) and calculate the Total Gold Value for each type to see what is worth selling.
Requirements:
- Create a function
sort_loot(loot_log):- Input: A list of strings. Format:
"ItemType:ItemName:GoldValue". - Logic: Parse the list and build a dictionary:
- Key: ItemType (String)
- Value: A List of Tuples, where each tuple is
(ItemName, GoldValue).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
appraise_inventory(loot_dict):- Input: The dictionary from step 1.
- Logic: Loop through each item type. Sum the gold values of all items in that type’s list.
- Output: Print the Item Type and the Total Value.
Testing Inputs (Copy this into your code):
loot_log = [
"Weapon:Iron Sword:150",
"Potion:Health Potion:10",
"Armor:Leather Vest:80",
"Weapon:Steel Dagger:120",
"Potion:Mana Potion:15",
"Armor:Iron Helm:50"
]
Expected Output:
Weapon: 270 Gold
Potion: 25 Gold
Armor: 130 Gold
Variant 9: The Monthly Expense Manager
You are building a personal finance tool. You have a raw list of credit card transactions. You need to group the transactions by Category (e.g., Food, Gas) and calculate the Total Cost for each category to check your budget.
Requirements:
- Create a function
group_expenses(transaction_list):- Input: A list of strings. Format:
"Date/Category/Cost". - Logic: Parse the list and build a dictionary:
- Key: Category (String)
- Value: A List of Tuples, where each tuple is
(Date, Cost).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
summarize_budget(expense_dict):- Input: The dictionary from step 1.
- Logic: Loop through each category. Sum the costs of all transactions in that category’s list.
- Output: Print the Category and the Total Cost.
Testing Inputs (Copy this into your code):
transaction_list = [
"01-Oct/Food/15.50",
"02-Oct/Gas/40.00",
"03-Oct/Food/12.25",
"04-Oct/Rent/800.00",
"05-Oct/Gas/35.00",
"05-Oct/Food/8.75"
]
Expected Output:
Food: $36.50 total
Gas: $75.00 total
Rent: $800.00 total
Variant 10: The Basketball Scoreboard
You are the scorekeeper for a basketball game. The referee gives you a log of scoring plays in a specific format. You need to organize the scoring by Player and calculate the Total Points each player scored to determine the MVP.
Requirements:
- Create a function
parse_game_log(score_log):- Input: A list of strings. Format:
"PlayerName#PlayType#Points". - Logic: Parse the list and build a dictionary:
- Key: PlayerName (String)
- Value: A List of Tuples, where each tuple is
(PlayType, Points).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
print_player_totals(game_dict):- Input: The dictionary from step 1.
- Logic: Loop through each player. Sum the points of all plays in that player’s list.
- Output: Print the Player Name and the Total Points.
Testing Inputs (Copy this into your code):
score_log = [
"Jordan#Dunk#2",
"Curry#3Pointer#3",
"Jordan#FreeThrow#1",
"LeBron#Layup#2",
"Curry#Layup#2",
"LeBron#3Pointer#3"
]
Expected Output:
Jordan: 3 points total
Curry: 5 points total
LeBron: 5 points total
Variant 11: The Network Data Monitor
You are an IT administrator monitoring Wi-Fi usage. The router logs data consumption by department. You need to group the usage logs by Department and calculate the Total Megabytes (MB) used to see who is slowing down the network.
Requirements:
- Create a function
track_usage(data_log):- Input: A list of strings. Format:
"Department;User;Megabytes". - Logic: Parse the list and build a dictionary:
- Key: Department (String)
- Value: A List of Tuples, where each tuple is
(User, Megabytes).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
audit_departments(network_dict):- Input: The dictionary from step 1.
- Logic: Loop through each department. Sum the megabytes of all entries in that department’s list.
- Output: Print the Department and the Total MB.
Testing Inputs (Copy this into your code):
data_log = [
"Sales;Alice;500",
"Engineering;Bob;1200",
"Sales;Charlie;300",
"HR;David;150",
"Engineering;Eve;800",
"HR;Frank;100"
]
Expected Output:
Sales: 800 MB total
Engineering: 2000 MB total
HR: 250 MB total
Variant 12: The Box Office Report
You manage a movie theater. You have a list of ticket sales from different showtimes. You need to group the sales by Movie Title and calculate the Total Tickets Sold for each movie to decide which ones to keep showing next week.
Requirements:
- Create a function
organize_sales(ticket_log):- Input: A list of strings. Format:
"MovieTitle::ShowTime::TicketsSold". - Logic: Parse the list and build a dictionary:
- Key: MovieTitle (String)
- Value: A List of Tuples, where each tuple is
(ShowTime, TicketsSold).
- Return: The dictionary.
- Input: A list of strings. Format:
- Create a function
calculate_box_office(cinema_dict):- Input: The dictionary from step 1.
- Logic: Loop through each movie. Sum the tickets sold from all showtimes in that movie’s list.
- Output: Print the Movie Title and the Total Tickets.
Testing Inputs (Copy this into your code):
ticket_log = [
"Avatar::10:00AM::50",
"Titanic::11:00AM::30",
"Avatar::2:00PM::100",
"StarWars::1:00PM::80",
"Titanic::4:00PM::40",
"StarWars::5:00PM::120"
]
Expected Output:
Avatar: 150 tickets sold
Titanic: 70 tickets sold
StarWars: 200 tickets sold
Extra Problem: The Factory Resource Planner
You are writing the logic for a factory’s manufacturing system. You have three pieces of data:
- Blueprints: A dictionary defining what parts are needed to build one unit of a product. (Nested Dictionary).
- Production Queue: A list of products that have been ordered and need to be built today.
- Warehouse Stock: A dictionary of the raw materials currently available.
Your Goal: Write a program that determines if you have enough materials to build the entire queue.
- If you have enough, print “Production Approved”.
- If you do not have enough, generate a “Shortage Report” showing exactly which materials are missing and by how much.
Logic Requirements:
- You cannot check orders one by one against the stock (because one order might use up the steel needed for the next order). You must calculate the Grand Total of materials needed for the entire queue first.
- Compare this Grand Total against the Warehouse Stock.
- If
Needed > Stock, the difference is the shortage. - If a material is needed but is missing completely from the Warehouse dictionary, count the entire amount as a shortage.
Input Data (Copy into your code):
# How to build things (Product -> {Material: Qty})
blueprints = {
"Robot": {"Steel": 50, "Microchip": 5, "Wire": 20},
"Drone": {"Plastic": 10, "Microchip": 2, "Battery": 1},
"Console": {"Plastic": 50, "Microchip": 10, "Wire": 5}
}
# What we have right now
warehouse_stock = {
"Steel": 200,
"Plastic": 100,
"Microchip": 20, # We have 20, but we might need more!
"Wire": 100,
"Battery": 50
}
# What we need to build today
production_queue = ["Robot", "Drone", "Robot", "Console"]
Expected Output:
SHORTAGE REPORT:
Material: Steel | Required: 100 | Have: 200 | Status: OK
Material: Microchip | Required: 22 | Have: 20 | MISSING: 2
Material: Wire | Required: 45 | Have: 100 | Status: OK
Material: Plastic | Required: 60 | Have: 100 | Status: OK
Material: Battery | Required: 1 | Have: 50 | Status: OK
CONCLUSION:
Production Halted. Missing materials.
This content will be available starting December 04, 2025.