Teacher's Cheat Sheet 🍎

Common Week 1 Python Errors

Helping students debug their "Digital Physics Labs"

1. The "Missing Label" (NameError)

Most common for beginners.

What the student sees: NameError: name 'gravity' is not defined

The Physics Context: They tried to use a constant (like ) without telling the computer what it equals first.

The Fix: Ensure the variable is defined above the calculation.
<span class="solution">Check for typos: gravty vs gravity.</span>

2. The "Math Logic" (TypeError)

Mixing text and numbers.

What the student sees: TypeError: can only concatenate str (not "float") to str

The Physics Context: They tried to multiply a word by a number.
result = "Mass" * 9.8

The Fix: Make sure variables used in math don't have quotation marks.
<span class="solution">Quotes = Text labels. No quotes = Numerical values.</span>

3. The "Grammar Mistake" (SyntaxError)

Forgetting the Python "Rules."

What the student sees: SyntaxError: invalid syntax (often pointing at a bracket or equals sign).

Common Causes in Physics:

  • Writing instead of 2 * a (Python needs the * symbol).
  • Forgetting to close a parenthesis: print(voltage.

The Fix: <span class="solution">Remind them: "Computer math requires explicit operators (+, -, *, /)."</span>

4. The "Indentation" Error

Python's "Paragraph" structure.

What the student sees: IndentationError: unexpected indent

The Context: A student accidentally hit 'Space' or 'Tab' at the start of a line.

The Fix: In Python, every line in a basic script should start at the exact same left margin.
<span class="solution">Align everything to the left for Week 1.</span>

5. The "Silent Error" (Logic Error)

The hardest to catch!

What the student sees: No red text, but a wrong answer.

The Physics Context: potential_energy = mass * g + height (using + instead of *).

The Fix: This is where the Architect shines.
<span class="solution">Ask the student: "Does the unit of your answer match the physics? Check your formula line."</span>

Quick Debugging Workflow for Teachers

  1. Read the bottom line: The error message usually tells you exactly what's wrong.
  2. Look for the Arrow: Python often prints a small ^ pointing to where it got confused.
  3. Check the Colors:
    • Green/Blue: Variables/Numbers.
    • Red/Orange: Text strings.
    • Black: Formulas and basic commands.

Teaching Tip: "Break it to Make it"

Encourage students to intentionally cause these errors.

  • "How do you make a NameError happen?"
  • "How do you make a SyntaxError?"

The Goal: By the end of Week 1, students shouldn't be afraid of the red text—they should see it as a GPS navigation system for their logic.