🐸

The Crash

Python Basicspython-architect-07-crash
Reward: 80 XP
|

Hoppy is flying the airship when suddenly... alarm bells ring! The control panel is flashing red.

"Alert! Code integrity compromised!"

To save the ship, we must understand why it crashed. Errors are not failures; they are clues.

Types of Crashes

Just like a machine can break in different ways, code has different error types:

  1. SyntaxError: You broke the rules of the language (like bad grammar).
  2. NameError: You tried to use something that doesn't exist (like calling a ghost).
  3. TypeError: You tried to combine things that don't match (like adding text to a number).
# SyntaxError (Missing colon)
if True
  pass

# NameError (Typo)
print(x) # x is not defined

# TypeError (Math with text)
"score: " + 100
1
Fix the SyntaxError

The greet function definition is missing a colon :. Add it.

2
Fix the NameError

The variable message is defined, but we tried to print mesage. Fix the typo.

3
Fix the TypeError

We cannot add the string "Power level: " to the integer 9000. Convert the number to a string using str(9000).

Read the "Crystal Ball" (Terminal) output carefully. It points to the exact line number where the crash happened!

Suggested Solution
Expand
Solution:
def greet(name):
  print("Welcome, " + name) # SytaxError fixed: added :

message = "System Online" # NameError fixed: typing mesage -> message
print(message)

# TypeError fixed: turn 9000 into "9000"
print("Power level: " + str(9000))
Advanced Tips
Want more? Click to expand

F. Debugging Wisdom

  • Read the Error Name: It usually tells you exactly what went wrong.
  • Check the Line Number: The error message tells you where to look (line 5).
  • Don't Panic: Even professional architects break code every day.
Loading...
Terminal
Terminal
Ready to run...