Lesson 19/48 ยท ๐Ÿ”€ Making Decisions
๐Ÿ”€ Making DecisionsLesson 19/48
Phase 2 ยท Making Decisions20 min

The Error Detective

Errors are clues, not failures, learn to read them like a pro

Every programmer gets errors. Every single day.
Professional developers with 10 years of experience still get errors. The difference between a beginner and an expert isn't that experts don't get errors, it's that experts can read the error message and know exactly what to fix.
This lesson is about building that skill.
When Python crashes, it tells you three things:1. Which file and line number the error occurred on2. The type of error (SyntaxError, NameError, etc.)3. A description of what went wrong
Always read the error from bottom to top, the bottom is the most specific.
The 4 most common errors for beginners:
SyntaxError, Python can't understand the code at all. Usually a typo, missing colon, or mismatched bracket.SyntaxError: invalid syntax or SyntaxError: expected ':'
NameError, You used a variable name that doesn't exist yet.NameError: name 'usre_name' is not defined (typo: 'usre' instead of 'user')
TypeError, You tried to do something with the wrong type.TypeError: can only concatenate str (not "int") to str
IndentationError, Python uses indentation to structure code. Wrong indentation breaks everything.IndentationError: expected an indented block
Reading a tracebackpython
# If you saw this error:
#
# Traceback (most recent call last):
#   File "solution.py", line 3, in <module>
#     print("Hello, " + name)
# NameError: name 'name' is not defined
#
# Translation:
# - Line 3 is where it crashed
# - NameError means a variable called 'name' doesn't exist
# - Fix: you probably have a typo, or forgot to define name first

name = "Alice"   # Define it first!
print("Hello, " + name)
Debugging process:1. Read the error type, which category is it?2. Read the line number, go to that line3. Look around that line, sometimes the actual bug is 1-2 lines above4. Google the exact error message if you're still stuck, you're never the first person to see it
๐ŸŽฏ

Phase Complete!

Making Decisions

When would you use `if/elif/else` vs a boolean expression? Describe a real-world scenario from DevOps or cloud engineering where you'd use conditional logic.

0/500

Practice Exercises

0/4 solved
Exercise 1 of 4easyFix the Bug
โฑ 00:00

Fix the SyntaxError

This code has a SyntaxError. Find and fix it.Expected output: Hello, World!
solution.py
1 / 4
Exercise 2 of 4easyFix the Bug
โฑ 00:00

Fix the NameError

This code crashes with a NameError. Fix it.Expected output: My name is Alice and I am 25 years old.
solution.py
2 / 4
Exercise 3 of 4easyFix the Bug
โฑ 00:00

Fix the TypeError

This code crashes with a TypeError. Fix it so it prints:You have 3 unread messages.
solution.py
3 / 4
Exercise 4 of 4easyFix the Bug
โฑ 00:00

Fix the IndentationError

This code has an IndentationError. Fix the indentation.Expected output:5 is positive
solution.py
4 / 4
Solve all 4 exercises to unlock completion