Superversity
← All projects

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

  1. Read the CSV one row at a time

    2 hr

    Make

    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.

    Check

    The script lists six rows. The title that contains commas still occupies one CSV field.

    Python · CSV and DictReader ↗
  2. Group pages by category

    3 hr

    Make

    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.

    Check

    You get Design 56, History 25, and Science 19. Their combined total is 100.

    Python · Dictionaries ↗
  3. Try a bad row

    3 hr

    Make

    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.

    Check

    Your program tells you what to fix instead of silently treating an invalid number as zero.

    Python · Handling exceptions ↗
  4. Run it with a second log

    2 hr

    Make

    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.

    Check

    You can run the same script on either CSV by changing the file path, and your totals match a hand count.

    Python · argparse ↗