Minu's Games logo
MINU'S ROBOTICS

A Minu's Games EdTech Lab

← Code & Cognition
Day 15 of 30Real Python & Data

🐞Errors & Debugging

🎯 Today's objective

Read errors and fix bugs calmly with try/except.

📖 Key concepts

  • Read the traceback bottom-up
  • Common: SyntaxError, NameError, TypeError, ValueError
  • try/except handles errors gracefully
  • Print/inspect to debug

💻 Try this code

try:
    n = int(input("A number: "))
    print(100 / n)
except ValueError:
    print("That wasn't a number.")
except ZeroDivisionError:
    print("Can't divide by zero.")

👥 Learn it your way

🧒 Young Explorers

Errors aren’t failure — they’re the computer telling you exactly what to fix.

Your task

Take a program that crashes on bad input and wrap it so it asks again instead.

💼 Professionals

Catch specific exceptions, never bare except; fail loud in dev, gracefully in prod.

Your task

Write safe_divide(a, b) that returns None and logs a message on divide-by-zero.

🤖 AI connection

Models "fail" too — bad data, wrong shapes, NaNs. The same calm, systematic debugging you learn here is exactly how ML engineers fix broken pipelines.

✅ Quick check

Which way do you read a traceback first?

Bottom-up — the last line names the actual error.

Why avoid a bare except?

It hides real bugs by catching everything silently.