Week 9 Homework: Debugging with AI Assistance

Purpose

You don't need to be able to write fluent Python — but you do need to be able to read it, reason about what it's trying to do, and figure out why it's broken. In this assignment, you'll practice that skill on code that uses syntax you haven't been taught yet. This is intentional: real problem-solvers constantly run into unfamiliar syntax, and knowing how to investigate it (with help from AI tools) is just as important as knowing the syntax itself.

Instructions

For each of the 3 problems below:

  1. Read the code carefully. It contains syntax you haven't seen in class, and it has a bug.
  2. Use an AI tool to help you understand it. Try two of the following: Gemini, Claude, Copilot, ChatGPT, Mistral Vibe.
  3. In your own words (English, not code), explain:
    • What the code is trying to do
    • What's actually wrong with it
  4. Fix it. Write the corrected code. Make sure to include explicit types (e.g. int, float)
  5. Repeat for all 3 problems, using AI to help each time.

After completing all 3 problems, answer the reflection questions at the end.


Problem 1

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_squares = [n**2 for n in numbers if n % 2 = 0]
print(even_squares)

What is this code trying to do?

What is wrong with it?

What was your AI prompt?

Your fix (corrected code):

What does ** do?


Problem 2

names = ["Ava", "Liam", "Noah"]
scores = [92, 85, 78]

grade_report = {name: score for name score in zip(names, scores)}
print(grade_report)

What is this code trying to do?

What is wrong with it?

What was your AI prompt?

Your fix (corrected code):

What are the {} for?

What does zip mean?


Problem 3

students = [("Maya", 88), ("Chen", 95), ("Priya", 79)]

sorted_students = sorted(students, key = lambda s: s[2])
print(sorted_students)

What is this code trying to do?

What is wrong with it?

What was your AI prompt?

Your fix (corrected code):

What does lambda mean?


Which AI Tools Did You Use?

Reflection Questions

  1. Which of the AI tools did you prefer overall? Why?

  2. Did your preference depend on what you were asking (e.g., one AI was better at explaining, another was better at just giving you the fix)? Is this surprising to you or not? Why or why not?

  3. (Optional but encouraged) Was there ever a moment where the AI's explanation didn't quite make sense to you, or seemed wrong? What did you do?


Submission Notes for Students