Python project
Automate a reading log
Take a six-row reading log and write a reusable Python program that totals pages by category. Use a small input where you can check the arithmetic by hand.
What you’ll finish with
A script that reads a CSV path, prints totals by category, and gives a clear message for a bad row. The reference solution is there to compare once you have a working version.Build it in 4 steps
-
Read the CSV one row at a time
2 hrMake
Download both starter files to one folder and run python3 read-log.py reading-log.csv. Find the DictReader loop and identify which column each value came from.
Python · CSV and DictReader ↗Check
The script lists six rows. The title that contains commas still occupies one CSV field.
-
Group pages by category
3 hrMake
Convert each pages value to an integer. Keep a dictionary with category names as keys. For each row, add that row’s pages to the current total for its category.
Python · Dictionaries ↗Check
You get Design 56, History 25, and Science 19. Their combined total is 100.
-
Try a bad row
3 hrMake
Make a copy of the CSV and put words in one pages cell. Handle the conversion error and print which line needs repair before producing a total.
Python · Handling exceptions ↗Check
Your program tells you what to fix instead of silently treating an invalid number as zero.
-
Run it with a second log
2 hrMake
Use a second CSV with the same headers. Add a short note explaining the required columns and how to run your script. Compare with the reference once you’ve tried your own.
Python · argparse ↗Check
You can run the same script on either CSV by changing the file path, and your totals match a hand count.