๐ด๐ ๐ฃ Three Error Types
| Type | What happens | Example |
| Syntax | Won't run | Missing colon |
| Logic | Wrong answer | = instead of == |
| Runtime | Crashes | Divide by zero |
Syntax errors โ common causes:
if x > 0:
for i in range(5):
def greet(name):
if x == 5:
x = 5
print("hello")
โ ๏ธ Python tells you the LINE NUMBER in error messages!
๐ The 5-Step Debug Process
1. READ โ Read the error message
2. LOCATE โ Find the line with the bug
3. UNDERSTAND โ Why is it wrong?
4. FIX โ Make ONE change
5. TEST โ Run again, verify
Debugging questions to ask:
๐ก Fix ONE thing at a time โ then test!
Print debugging:
print("DEBUG: x =", x)
print("DEBUG: list =", my_list)
print("DEBUG: reached line 15")
๐ฃ Runtime Errors
| Error | Cause |
| ZeroDivisionError | x / 0 |
| NameError | Undefined variable |
| IndexError | list[10] (too big) |
| ValueError | int("abc") |
| TypeError | "a" + 5 |
| AttributeError | Wrong method |
Reading error messages:
Traceback (most recent call last):
File "main.py", line 5, in <module>
result = 10 / 0
ZeroDivisionError: division by zero
๐ก๏ธ try / except
Basic structure:
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
Multiple except blocks:
try:
x = int(input("Enter number: "))
result = 100 / x
print(result)
except ValueError:
print("Not a valid number!")
except ZeroDivisionError:
print("Cannot divide by zero!")
With else and finally:
try:
result = 10 / 2
except ZeroDivisionError:
print("Error!")
else:
print("Success:", result)
finally:
print("Always runs")
โ ๏ธ Only catch errors you expect!
๐งช Writing Tests
Simple test cases:
print(is_even(4) == True)
print(is_even(7) == False)
print(is_even(0) == True)
Using assert:
assert is_even(4) == True
assert is_even(7) == False
assert get_grade(95) == "A"
assert get_grade(85) == "B"
print("All tests passed! โ
")
Test types to include:
| Type | Example |
| Normal case | is_even(4) โ True |
| Edge case | is_even(0) โ True |
| Boundary | get_grade(90) โ "A" |
| Negative | is_even(-2) โ True |
๐ฏ Edge Cases & Boundaries
Common edge cases:
| Situation | Edge case to test |
| List function | Empty list [] |
| Number function | Zero, negative |
| String function | Empty string "" |
| Division | Divisor = 0 |
| Index | First and last item |
Boundary testing example:
get_grade(90)
get_grade(89)
get_grade(80)
get_grade(79)
get_grade(0)
get_grade(100)
๐ก Test the EXACT boundary value AND one above/below!
๐ง Logic Error Checklist
| Check | Common mistake |
| Operators | < vs >, == vs != |
| Values | Wrong return value |
| Case | "Nova" โ "nova" |
| Off-by-one | range(1,10) misses 10 |
| Accumulator | Start at 0 vs 1 |
| Condition order | Most specific first |
Trace technique:
def get_grade(score):
print(f"DEBUG: score={score}")
if score >= 90:
print("DEBUG: returning A")
return "A"
๐ก Trace = follow code step by step manually
๐ XP Ranks & Worlds
| Rank | XP | Icon |
| Cadet | 0 | ๐ฑ |
| Explorer | 500 | ๐ญ |
| Navigator | 1,500 | ๐งญ |
| Captain | 3,000 | โก |
| Admiral | 6,000 | ๐ |
| World | Year | Theme |
| ๐ Syntax World | 3 | Sequences |
| ๐ฎ Algorithm Alley | 4 | Logic |
| ๐ Syntax Station | 5 | Loops |
| ๐๏ธ Debugging Dunes | 6 | Debugging |
| ๐จ Creativity Cluster | 7 | Creative |
๐ Canon Authority: Katarzyna Kalina vel Kalinowska