Week 10 Homework: Reading, Tracing, and Critiquing AI-Generated Code

Background

For this assignment, you were given a short Python program that was generated by an AI coding assistant. The code runs without crashing, but it was never reviewed by a human, so the documentation is poor and the variable names don't tell you much about what's going on. This is a very common real-world situation: AI tools can produce code quickly, but you are still responsible for understanding it, checking that it's correct, and deciding whether it's good enough to use.

You will not be graded on writing or fixing Python code in this assignment. You are being graded on how well you can reason about, trace, and critique code that someone (or something) else wrote.

The file `class_report.ipynb is provided with this assignment. Do not run it until you reach Part 3 — Parts 1 and 2 must be done without running anything in Python.


Part 1 — Reason About It (no Jupyter)

Read through class_report.py on paper or on screen, but do not run it.

  1. In your own words, write 2–4 sentences describing what you think this program is supposed to do overall.

  2. For each of the four functions (calc, grade, top, process), write one sentence describing what you believe it does.

  3. Identify the purpose of each variable in the table below by writing a short, better name for it than the one the original author chose:


Part 2 — Trace It (no Jupyter)

The program is called with this input:

data = [95, 88, 72, 60, 90, 100, 45, 80]
process(data)

By hand, trace the execution and fill in the table with what you predict the program will print, line by line, in order.

Show your work for at least the grade() calls — for each of the 8 scores, write down which if/elif branch you believe it takes and why.


Part 3 — Run It (in Jupyter)

  1. Run class_report.ipynb exactly as given, using the data list above.
  2. Copy the actual output here.
  3. Compare the actual output to your Part 2 prediction. Answer:
    • Did it match your prediction? If not, exactly where did it diverge (which line, which score)?
    • For any score where your prediction was wrong, look closely at the grade() function. What is it actually doing at the boundary values (93, 85, 77, 70)? Is that what you assumed a grading scale would do?
    • Was this a bug, or just a design decision you didn't expect? Explain your reasoning either way.

Part 4 — Critique It

You do not need to fix anything. Instead, write a short (roughly half a page) high-level code review, as if you were leaving feedback for a teammate. Address:

  1. Correctness — Based on Part 3, does the code do what a reasonable person would expect a "class report" or "grading" program to do? Are there any behaviors you'd flag as likely bugs?
  2. What you like — Name at least one thing about the structure of this code that is reasonable or well organized (for example: is it broken into functions sensibly? Is there repeated logic that was avoided?).
  3. Documentation and naming — Is it clear, from reading the code alone, what each function and variable is for? What's missing?
  4. Where would you spend effort? — If you had 20 minutes to improve this program before handing it to a client, what would you prioritize fixing first, second, and third? Justify your ordering — why is one issue more important than another?

Submission

Submit your completed Parts 1–4 as a single document (PDF or Word). Include your tables, your traced predictions, the actual output you got from running the code, and your written critique.

A note on using AI tools for this assignment

You may use an AI assistant to help you understand unfamiliar Python syntax (for example, asking "what does range(1, len(d)) do?"). You may not ask an AI assistant to generate your trace predictions, your critique, or your answers to Part 3 for you — the point of this assignment is to build your own ability to read and reason about code, which is exactly the skill you'll need when an AI assistant hands you code in the future.