← Computer Programming I

Variant 1: Retail Revenue Analyzer

You have been hired by a retail store to analyze their daily sales log. The file contains a list of transactions, but the data needs to be aggregated by category to understand which store sections are performing best. You also need to flag any high-value individual sales for managerial review.

Input File Format The file sales_data.txt contains lines in this format: Product,Category,Price,Quantity

  • Example: Laptop,Electronics,1200.00,1

Requirements Create a Python program with the following specific structure:

  1. Function 1: process_sales_data(filename)
    • Input: A string representing the filename.
    • Logic:
      • Open the file using with open(...).
      • Read the file line by line.
      • Use try/except to handle lines with corrupted data (non-numeric price/quantity).
      • Calculate revenue for each line: Revenue = Price * Quantity.
      • Aggregation: Use a Dictionary to sum the total revenue for each Category.
      • Filtering: If a single transaction’s revenue is greater than $500, add the product name and its revenue to a List.
    • Output: Return two items: the dictionary of category totals and the list of high-value transactions.
  2. Function 2: save_revenue_report(category_totals, high_value_items)
    • Input: The dictionary and list returned from the previous function.
    • Logic:
      • Open a new file called revenue_report.txt in write mode.
      • Write a header “CATEGORY REVENUE SUMMARY”.
      • Loop through the dictionary and write each category and its total (formatted to 2 decimal places).
      • Write a separator line.
      • Write a header “HIGH VALUE TRANSACTIONS (> $500)”.
      • Loop through the list and write the high-value items.
  3. Main Execution: call your functions to run the program.

Test Input (sales_data.txt)

T-Shirt,Clothing,20.00,5
Laptop,Electronics,1000.00,1
Toaster,Home,30.00,2
Jeans,Clothing,50.00,2
TV,Electronics,600.00,2
BadLine,NoNumbers,Here
Blender,Home,40.00,1
Sneakers,Clothing,120.00,1

Expected Output (revenue_report.txt)

CATEGORY REVENUE SUMMARY
------------------------
Clothing: $320.00
Electronics: $2200.00
Home: $100.00

HIGH VALUE TRANSACTIONS (> $500)
--------------------------------
Laptop: $1000.00
TV: $1200.00

Variant 2: Department Payroll Calculator

You are building a payroll processing tool for Human Resources. You have a raw timesheet file, and you need to calculate the total cost of wages per department. Additionally, HR needs a specific list of employees who are working overtime (more than 40 hours) to ensure compliance with labor laws.

Input File Format The file timesheet.txt contains lines in this format: EmployeeName,Department,HoursWorked,HourlyRate

  • Example: Alice,Sales,45,20.00

Requirements Create a Python program with the following specific structure:

  1. Function 1: calculate_payroll(filename)
    • Input: A string representing the filename.
    • Logic:
      • Open the file using with open(...).
      • Read the file line by line.
      • Use try/except to handle lines where Hours or Rate are not numbers.
      • Calculate total pay for each person: Pay = Hours * Rate.
      • Aggregation: Use a Dictionary to sum the total pay cost for each Department.
      • Filtering: If an employee’s HoursWorked is greater than 40, add their name and hours to a List.
    • Output: Return two items: the dictionary of department costs and the list of overtime employees.
  2. Function 2: generate_payroll_report(dept_costs, overtime_staff)
    • Input: The dictionary and list returned from the previous function.
    • Logic:
      • Open a new file called payroll_summary.txt in write mode.
      • Write a header “DEPARTMENT WAGE COSTS”.
      • Loop through the dictionary and write each department and its total cost.
      • Write a separator line.
      • Write a header “OVERTIME ALERTS (> 40 Hours)”.
      • Loop through the list and write the employee names and their hours.
  3. Main Execution: call your functions to run the program.

Test Input (timesheet.txt)

Alice,Sales,45,25.00
Bob,IT,40,35.00
Charlie,Sales,38,25.00
David,IT,50,35.00
Eve,HR,40,30.00
Frank,Sales,40,25.00
Error,Data,Missing
Grace,HR,42,30.00

Expected Output (payroll_summary.txt)

DEPARTMENT WAGE COSTS
---------------------
Sales: $3075.00
IT: $3150.00
HR: $2460.00

OVERTIME ALERTS (> 40 Hours)
----------------------------
Alice (45 hours)
David (50 hours)
Grace (42 hours)

Variant 3: Library Fine Tracker

A library needs your help analyzing their overdue books log. They want to know which book genres are generating the most revenue from fines. They also need to identify “Severely Overdue” books (late by more than 30 days) so they can send physical notices to those borrowers.

Input File Format The file overdue_log.txt contains lines in this format: BookTitle,Genre,DaysOverdue,FinePerDay

  • Example: The Hobbit,Fantasy,5,0.50

Requirements Create a Python program with the following specific structure:

  1. Function 1: analyze_fines(filename)
    • Input: A string representing the filename.
    • Logic:
      • Open the file using with open(...).
      • Read the file line by line.
      • Use try/except to handle lines with invalid numeric data.
      • Calculate the total fine: TotalFine = DaysOverdue * FinePerDay.
      • Aggregation: Use a Dictionary to sum the total fines collected for each Genre.
      • Filtering: If DaysOverdue is greater than 30, add the Book Title and Days Overdue to a List.
    • Output: Return two items: the dictionary of genre totals and the list of severely overdue books.
  2. Function 2: save_fine_report(genre_totals, severe_books)
    • Input: The dictionary and list returned from the previous function.
    • Logic:
      • Open a new file called fine_report.txt in write mode.
      • Write a header “GENRE FINE REVENUE”.
      • Loop through the dictionary and write each genre and its collected fines.
      • Write a separator line.
      • Write a header “SEVERE DELAYS (> 30 Days)”.
      • Loop through the list and write the book titles and how many days late they are.
  3. Main Execution: call your functions to run the program.

Test Input (overdue_log.txt)

1984,SciFi,35,0.25
The Hobbit,Fantasy,5,0.50
Calculus,Textbook,45,1.00
Dune,SciFi,10,0.25
Mistborn,Fantasy,12,0.50
Broken,Line,Here
Physics,Textbook,2,1.00
Harry Potter,Fantasy,3,0.50

Expected Output (fine_report.txt)

GENRE FINE REVENUE
------------------
SciFi: $11.25
Fantasy: $10.00
Textbook: $47.00

SEVERE DELAYS (> 30 Days)
-------------------------
1984 (35 days)
Calculus (45 days)

Variant 4: Academic Performance Tracker

You are a teacher assistant helping to process exam grades. The file contains scores for two different parts of an exam. You need to calculate the total score for each student, find the total points earned per subject (to see which subject is easiest), and identify students who are failing (total score below 100) so they can be offered tutoring.

Input File Format The file exam_scores.txt contains lines in this format: StudentName,Subject,Part1Score,Part2Score

  • Example: Alice,Math,45,40

Requirements Create a Python program with the following specific structure:

  1. Function 1: process_exam_scores(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric scores with try/except.
      • Calculate TotalScore = Part1Score + Part2Score.
      • Aggregation: Use a Dictionary to sum the TotalScore for each Subject.
      • Filtering: If TotalScore is less than 100, add the Student Name and their Total Score to a List.
    • Output: Return the dictionary of subject totals and the list of failing students.
  2. Function 2: save_grade_report(subject_totals, failing_students)
    • Logic:
      • Open grade_report.txt in write mode.
      • Write header: “SUBJECT TOTAL POINTS”.
      • Write each subject and its aggregated total.
      • Write header: “AT RISK STUDENTS (< 100 pts)”.
      • Write the list of students who need help.
  3. Main Execution: Call your functions.

Test Input (exam_scores.txt)

John,Math,55,60
Sarah,Science,40,45
Mike,Math,30,40
Emma,History,80,90
David,Science,95,90
BadLine,Data,Missing
Chris,History,20,30

Expected Output (grade_report.txt)

SUBJECT TOTAL POINTS
--------------------
Math: 185
Science: 270
History: 220

AT RISK STUDENTS (< 100 pts)
----------------------------
Sarah (85 pts)
Mike (70 pts)
Chris (50 pts)

Variant 5: Warehouse Inventory Auditor

You work in logistics. You have a list of products stored in different warehouse zones. Each product has stock on the Shelf and stock in the Backroom. You need to calculate the total stock for each product, find the total number of items stored in each Zone, and identify products with critically low stock (total items below 50) that need reordering.

Input File Format The file warehouse_stock.txt contains lines in this format: Product,Zone,ShelfQty,BackroomQty

  • Example: WidgetA,Zone1,20,10

Requirements Create a Python program with the following specific structure:

  1. Function 1: audit_inventory(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric quantities with try/except.
      • Calculate TotalStock = ShelfQty + BackroomQty.
      • Aggregation: Use a Dictionary to sum the TotalStock for each Zone.
      • Filtering: If TotalStock is less than 50, add the Product Name and its Total Stock to a List.
    • Output: Return the dictionary of zone totals and the list of low-stock items.
  2. Function 2: generate_reorder_list(zone_totals, low_stock_items)
    • Logic:
      • Open inventory_report.txt in write mode.
      • Write header: “ZONE INVENTORY COUNTS”.
      • Write each zone and its aggregated total items.
      • Write header: “REORDER ALERTS (< 50 items)”.
      • Write the list of products that need reordering.
  3. Main Execution: Call your functions.

Test Input (warehouse_stock.txt)

Hammer,ZoneA,100,50
Drill,ZoneB,20,10
Saw,ZoneA,30,15
Nails,ZoneC,200,300
Screws,ZoneB,10,10
Corrupt,Line,Error
Paint,ZoneC,40,5

Expected Output (inventory_report.txt)

ZONE INVENTORY COUNTS
---------------------
ZoneA: 195
ZoneB: 50
ZoneC: 545

REORDER ALERTS (< 50 items)
---------------------------
Drill (30 items)
Saw (45 items)
Screws (20 items)
Paint (45 items)

Variant 6: Digital Campaign Monitor

You are a digital marketer tracking ad campaigns across different social media platforms. The file tracks “Clicks” and “Shares” for each campaign. You need to calculate the Total Interactions for each campaign, find the total volume of interactions per Platform, and identify underperforming campaigns (total interactions below 1000) that should be cancelled.

Input File Format The file campaign_data.txt contains lines in this format: CampaignName,Platform,Clicks,Shares

  • Example: SummerSale,Instagram,500,200

Requirements Create a Python program with the following specific structure:

  1. Function 1: analyze_campaigns(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric metrics with try/except.
      • Calculate Interactions = Clicks + Shares.
      • Aggregation: Use a Dictionary to sum the Interactions for each Platform.
      • Filtering: If Interactions is less than 1000, add the Campaign Name and its Interactions to a List.
    • Output: Return the dictionary of platform totals and the list of low-performing campaigns.
  2. Function 2: save_marketing_report(platform_totals, bad_campaigns)
    • Logic:
      • Open marketing_summary.txt in write mode.
      • Write header: “PLATFORM TRAFFIC VOLUME”.
      • Write each platform and its aggregated interactions.
      • Write header: “CANCEL CAMPAIGNS (< 1000 actions)”.
      • Write the list of campaigns to stop.
  3. Main Execution: Call your functions.

Test Input (campaign_data.txt)

Promo1,Facebook,800,400
Promo2,Instagram,200,50
Promo3,Facebook,2000,500
Ad_A,TikTok,5000,3000
Ad_B,Instagram,400,300
Broken,Data,Here,Now
Ad_C,TikTok,100,50

Expected Output (marketing_summary.txt)

PLATFORM TRAFFIC VOLUME
-----------------------
Facebook: 3700
Instagram: 950
TikTok: 8150

CANCEL CAMPAIGNS (< 1000 actions)
---------------------------------
Promo2 (250 actions)
Ad_B (700 actions)
Ad_C (150 actions)

Variant 7: Soccer League Stat Tracker

You are the statistician for a local soccer league. You have a file containing the season’s data for various players. You need to calculate the total “Goal Contributions” (Goals + Assists) for each player, find the total contributions for each Team, and identify the “MVP Candidates” (players with more than 15 contributions).

Input File Format The file soccer_stats.txt contains lines in this format: PlayerName,TeamName,Goals,Assists

  • Example: Messi,InterMiami,20,10

Requirements Create a Python program with the following specific structure:

  1. Function 1: process_league_stats(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric data with try/except.
      • Calculate TotalContribution = Goals + Assists.
      • Aggregation: Use a Dictionary to sum the TotalContribution for each Team.
      • Filtering: If TotalContribution is greater than 15, add the Player Name and their Total to a List.
    • Output: Return the dictionary of team totals and the list of MVP candidates.
  2. Function 2: generate_season_summary(team_totals, mvp_list)
    • Logic:
      • Open season_summary.txt in write mode.
      • Write header: “TEAM PERFORMANCE (Total Contributions)”.
      • Write each team and its aggregated total.
      • Write header: “MVP CANDIDATES (> 15 contribs)”.
      • Write the list of top players.
  3. Main Execution: Call your functions.

Test Input (soccer_stats.txt)

Ronaldo,AlNassr,12,4
Messi,InterMiami,10,8
Suarez,InterMiami,8,5
Neymar,AlHilal,10,20
Bad,Data,Entry,Here
Benzema,AlIttihad,15,5
Modric,RealMadrid,2,10

Expected Output (season_summary.txt)

TEAM PERFORMANCE (Total Contributions)
--------------------------------------
AlNassr: 16
InterMiami: 31
AlHilal: 30
AlIttihad: 20
RealMadrid: 12

MVP CANDIDATES (> 15 contribs)
------------------------------
Ronaldo (16)
Messi (18)
Neymar (30)
Benzema (20)

Variant 8: Home Energy Auditor

You are writing software for a smart home system. The system logs energy usage (in kWh) for appliances during the Day and Night. You need to calculate the total energy consumed by each appliance, aggregate the total usage per Room, and identify “Power Hog” appliances (total usage greater than 10 kWh) that might need replacing.

Input File Format The file energy_log.txt contains lines in this format: Appliance,Room,DayUsage,NightUsage

  • Example: Fridge,Kitchen,2.5,3.0

Requirements Create a Python program with the following specific structure:

  1. Function 1: audit_energy_usage(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric usage data with try/except.
      • Calculate TotalUsage = DayUsage + NightUsage.
      • Aggregation: Use a Dictionary to sum the TotalUsage for each Room.
      • Filtering: If TotalUsage is greater than 10.0, add the Appliance Name and its Total Usage to a List.
    • Output: Return the dictionary of room totals and the list of power hogs.
  2. Function 2: save_energy_report(room_totals, power_hogs)
    • Logic:
      • Open energy_report.txt in write mode.
      • Write header: “ROOM ENERGY CONSUMPTION (kWh)”.
      • Write each room and its aggregated total.
      • Write header: “POWER HOGS (> 10 kWh)”.
      • Write the list of inefficient appliances.
  3. Main Execution: Call your functions.

Test Input (energy_log.txt)

Heater,LivingRoom,8.5,5.0
TV,LivingRoom,2.0,1.0
Oven,Kitchen,4.0,0.5
OldFreezer,Garage,6.0,7.0
Lamp,Bedroom,0.5,0.5
Error,Line,Missing,Data
AC_Unit,Bedroom,5.0,8.0

Expected Output (energy_report.txt)

ROOM ENERGY CONSUMPTION (kWh)
-----------------------------
LivingRoom: 16.5
Kitchen: 4.5
Garage: 13.0
Bedroom: 14.0

POWER HOGS (> 10 kWh)
---------------------
Heater (13.5 kWh)
OldFreezer (13.0 kWh)
AC_Unit (13.0 kWh)

Variant 9: Charity Donation Tracker

You are managing a charity fundraiser event. Donations come in via Cash or Check. You have a log of donors and which specific cause they supported. You need to calculate the total donation amount for each person, find the total money raised for each Cause, and identify “Gold Tier Donors” (people who gave more than $500).

Input File Format The file donations.txt contains lines in this format: DonorName,Cause,CashAmount,CheckAmount

  • Example: JohnDoe,AnimalShelter,100,50

Requirements Create a Python program with the following specific structure:

  1. Function 1: process_donations(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric amounts with try/except.
      • Calculate TotalDonation = CashAmount + CheckAmount.
      • Aggregation: Use a Dictionary to sum the TotalDonation for each Cause.
      • Filtering: If TotalDonation is greater than 500, add the Donor Name and their Total Donation to a List.
    • Output: Return the dictionary of cause totals and the list of top donors.
  2. Function 2: write_fundraising_report(cause_totals, top_donors)
    • Logic:
      • Open fundraising_summary.txt in write mode.
      • Write header: “FUNDS RAISED PER CAUSE”.
      • Write each cause and its aggregated total.
      • Write header: “GOLD TIER DONORS (> $500)”.
      • Write the list of top donors.
  3. Main Execution: Call your functions.

Test Input (donations.txt)

Alice,HomelessShelter,200,100
Bob,FoodBank,50,50
Charlie,HomelessShelter,400,200
Diana,AnimalRescue,1000,0
Corrupt,Line,No,Money
Eve,FoodBank,20,10
Frank,AnimalRescue,300,300

Expected Output (fundraising_summary.txt)

FUNDS RAISED PER CAUSE
----------------------
HomelessShelter: $900.00
FoodBank: $130.00
AnimalRescue: $1600.00

GOLD TIER DONORS (> $500)
-------------------------
Charlie ($600.00)
Diana ($1000.00)
Frank ($600.00)

Variant 10: Fitness Challenge Tracker

You are managing a community fitness challenge. Participants log the number of minutes they spend doing Cardio and Strength training each day. You need to calculate the total workout time for each person, find the total time spent on each Activity Type across all participants, and identify “Iron Athletes” (people who worked out for more than 90 minutes).

Input File Format The file workout_log.txt contains lines in this format: ParticipantName,ActivityType,CardioMinutes,StrengthMinutes

  • Example: John,Crossfit,30,45

Requirements Create a Python program with the following specific structure:

  1. Function 1: process_fitness_data(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric durations with try/except.
      • Calculate TotalMinutes = CardioMinutes + StrengthMinutes.
      • Aggregation: Use a Dictionary to sum the TotalMinutes for each ActivityType.
      • Filtering: If TotalMinutes is greater than 90, add the Participant Name and their Total Minutes to a List.
    • Output: Return the dictionary of activity totals and the list of Iron Athletes.
  2. Function 2: save_fitness_report(activity_totals, elite_athletes)
    • Logic:
      • Open fitness_report.txt in write mode.
      • Write header: “ACTIVITY TYPE TOTALS (Minutes)”.
      • Write each activity type and its aggregated total time.
      • Write header: “IRON ATHLETES (> 90 mins)”.
      • Write the list of top performers.
  3. Main Execution: Call your functions.

Test Input (workout_log.txt)

Sarah,Yoga,60,0
Mike,Crossfit,40,55
Emily,Running,90,10
David,Yoga,45,15
Invalid,Entry,No,Numbers
Chris,Crossfit,50,50
Anna,Running,30,0

Expected Output (fitness_report.txt)

ACTIVITY TYPE TOTALS (Minutes)
------------------------------
Yoga: 120
Crossfit: 195
Running: 130

IRON ATHLETES (> 90 mins)
-------------------------
Mike (95 mins)
Emily (100 mins)
Chris (100 mins)

Variant 11: City Traffic Surveyor

You are working for the city planning department. Sensors on various streets record the number of Cars and Trucks passing through during rush hour. You need to calculate the total vehicle volume for each street, aggregate the total traffic per District, and identify “Congested Streets” (total volume greater than 500 vehicles) that need traffic light adjustments.

Input File Format The file traffic_survey.txt contains lines in this format: StreetName,District,CarCount,TruckCount

  • Example: MainSt,Downtown,400,50

Requirements Create a Python program with the following specific structure:

  1. Function 1: analyze_traffic_flow(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric counts with try/except.
      • Calculate TotalVolume = CarCount + TruckCount.
      • Aggregation: Use a Dictionary to sum the TotalVolume for each District.
      • Filtering: If TotalVolume is greater than 500, add the Street Name and its Total Volume to a List.
    • Output: Return the dictionary of district totals and the list of congested streets.
  2. Function 2: write_traffic_report(district_totals, congested_streets)
    • Logic:
      • Open traffic_report.txt in write mode.
      • Write header: “DISTRICT TRAFFIC VOLUME”.
      • Write each district and its aggregated total.
      • Write header: “CONGESTED STREETS (> 500 vehicles)”.
      • Write the list of high-traffic streets.
  3. Main Execution: Call your functions.

Test Input (traffic_survey.txt)

MainSt,Downtown,450,100
Broadway,Downtown,300,50
OakAve,Suburbs,100,20
PineRd,Suburbs,50,10
Hwy101,Highway,800,400
Error,Line,Missing,Data
MarketSt,Downtown,500,200

Expected Output (traffic_report.txt)

DISTRICT TRAFFIC VOLUME
-----------------------
Downtown: 1600
Suburbs: 180
Highway: 1200

CONGESTED STREETS (> 500 vehicles)
----------------------------------
MainSt (550 vehicles)
Hwy101 (1200 vehicles)
MarketSt (700 vehicles)

Variant 12: Streamer Revenue Analyzer

You are analyzing the earnings of online content creators. The file logs the revenue earned from Advertisements and Subscriptions for different channels. You need to calculate the total earnings for each streamer, find the total revenue generated by each Content Category (e.g., Gaming, Music), and identify “Top Earners” (streamers who made more than $2000).

Input File Format The file streamer_income.txt contains lines in this format: ChannelName,Category,AdRevenue,SubRevenue

  • Example: Ninja,Gaming,1500,3000

Requirements Create a Python program with the following specific structure:

  1. Function 1: calculate_streamer_earnings(filename)
    • Logic:
      • Open the file using with open(...).
      • Read line by line, handling non-numeric currency data with try/except.
      • Calculate TotalEarnings = AdRevenue + SubRevenue.
      • Aggregation: Use a Dictionary to sum the TotalEarnings for each Category.
      • Filtering: If TotalEarnings is greater than 2000, add the Channel Name and their Total Earnings to a List.
    • Output: Return the dictionary of category totals and the list of top earners.
  2. Function 2: generate_income_statement(category_totals, top_earners)
    • Logic:
      • Open income_statement.txt in write mode.
      • Write header: “REVENUE BY CATEGORY”.
      • Write each category and its aggregated total.
      • Write header: “TOP EARNERS (> $2000)”.
      • Write the list of successful channels.
  3. Main Execution: Call your functions.

Test Input (streamer_income.txt)

PixelPlay,Gaming,800,500
ChefAnna,Cooking,1200,1000
GuitarGuy,Music,500,200
SpeedRun,Gaming,1500,1000
Broken,Row,No,Cash
TastyTreats,Cooking,300,100
ProGamer,Gaming,2000,3000

Expected Output (income_statement.txt)

REVENUE BY CATEGORY
-------------------
Gaming: $8800.00
Cooking: $2600.00
Music: $700.00

TOP EARNERS (> $2000)
---------------------
ChefAnna ($2200.00)
SpeedRun ($2500.00)
ProGamer ($5000.00)


This is a simplified alternative to the standard Week 12 assignments. If you choose to submit one of these options instead of the standard assignment, the maximum grade you can achieve is 60%.

Variant A: The Daily Expense Summer

You want to know how much money you spent this week. You have a simple text file where every line represents the cost of one item you bought. Your job is to write a program that reads these numbers and calculates the total amount spent.

Input File Format The file expenses.txt contains one number per line:

12.50
5.00
3.75
20.00
4.50
not_a_number
10.00

Requirements Write a Python program that:

  1. Defines a function calculate_total(filename).
  2. Opens the file using with open(...).
  3. Loops through every line in the file.
  4. Uses try/except to convert the line to a float.
    • If it converts successfully, add it to a total_spent variable.
    • If it fails (like “not_a_number”), print “Skipping invalid line” and continue.
  5. After the loop finishes, print the Total Spent and the count of how many valid items were processed.

Expected Output

Skipping invalid line
---------------------
Total Items: 6
Total Spent: $55.75

Hints

  • Use a variable like total = 0.0 before the loop starts.
  • Remember that line.strip() removes the invisible newline character.

Variant B: The RSVP Counter

You are organizing a party and have a list of guests. Some have said “Yes” they are coming, and some have said “No”. You need a program to count exactly how many people are confirmed to attend.

Input File Format The file guests.txt contains lines in the format Name,Response:

Alice,Yes
Bob,No
Charlie,Yes
David,Maybe
Eve,Yes
Frank,No

Requirements Write a Python program that:

  1. Defines a function count_attendees(filename).
  2. Opens the file using with open(...).
  3. Loops through every line.
  4. Splits the line into name and response using .split(",").
  5. Uses .strip() to clean up extra spaces around the response.
  6. Checks if the response is exactly equal to "Yes".
    • If it is, print the person’s name and add 1 to a guest_count variable.
  7. At the end, print the final count of attending guests.

Expected Output

Confirmed Guest: Alice
Confirmed Guest: Charlie
Confirmed Guest: Eve
---------------------
Total Attending: 3

Hints

  • When you split Alice,Yes, you get a list ["Alice", "Yes"]. The response is at index 1.
  • Strings are case-sensitive! “Yes” is not the same as “yes “. Use .strip().

Variant C: The High Score Finder

You have a file containing scores from a video game tournament. You need to find out which score was the highest and print it out.

Input File Format The file scores.txt contains one integer per line:

450
120
890
300
bad_data
950
500

Requirements Write a Python program that:

  1. Defines a function find_highest_score(filename).
  2. Opens the file using with open(...).
  3. Loops through every line.
  4. Uses try/except to convert the line to an int.
    • If valid, compare it to your current highest_score.
    • If the new number is bigger than highest_score, update your variable.
  5. After the loop, print the highest score found.

Expected Output

Processing scores...
Found new high score: 450
Found new high score: 890
Found new high score: 950
---------------------
Final High Score: 950

Hints

  • Start your highest_score variable at -1 or 0 before the loop begins.
  • Inside the try block, you will need an if statement: if current_score > highest_score: ...