Loading Python Environment...
This may take a few seconds.

The Art of Debugging

Writing code is easy. Making it work is the hard part. Let's practice fixing Syntax, Runtime, and Logic errors.

The 3 Types of Errors

As we move from single lines to longer programs, you will encounter bugs. Identifying which type of bug you have is 90% of the battle.

1. Syntax Error

Grammar mistakes. Python doesn't know how to read your code.

Ex: Missing parenthesis, typos in keywords.

2. Runtime Error

The code reads fine, but crashes while running.

Ex: Dividing by zero, using a variable that isn't defined.

3. Logic Error

The code runs, but gives the wrong answer.

Ex: Using + instead of *, order of operations.

Exercise 1

Fixing Syntax

This code attempts to print a message, but it won't run. Can you spot the syntax error?

Need a Hint?
Check the parentheses on line 3.
Output will appear here...
Exercise 1.2

The Quote Jam (Intermediate)

Strings in Python must be surrounded by matching quotes. But what if the text itself contains a quote?

Need a Hint?
If you use single quotes on the outside, you can't use them on the inside without escaping. Try double quotes "..." for the whole string.
Output will appear here...
Exercise 1.3

The Naming Conflict (Advanced)

Variables usually hold data, but they must follow strict naming rules. This code fails because the variable name is illegal.

Need a Hint?
Variable names cannot start with a number. Try moving the number to the end or using words.
Output will appear here...
Exercise 2

Fixing Runtime Errors

This code is grammatically correct, but it fails during execution. Scenario: You have 50 gold coins to share among a group of people.

Need a Hint?
Look at the value of the people variable. Can you divide by that number?
Output will appear here...
Exercise 2.2

The Ghost Variable (Intermediate)

Python is case-sensitive. Value and value are different things. This code crashes because it can't find the variable.

Need a Hint?
Check the capitalization of my_score in the print statement.
Output will appear here...
Exercise 2.3

The Type Clash (Advanced)

You can add numbers to numbers, and strings to strings. But mixing them causes a TypeError.

Need a Hint?
You cannot do math with a word. Try separating them with a comma in the print statement, or convert the number to string.
Output will appear here...
Exercise 3

Fixing Logic Errors (The Dangerous Ones)

Logic errors are dangerous because the program doesn't crash. It just lies to you.
Goal: Calculate the average of 10 and 20. The answer should be 15.

Need a Hint?
Check the Order of Operations. Does division or addition happen first?
Output will appear here...
Exercise 3.2

The Lost Power-Up (Intermediate)

You picked up a health potion, but your health didn't go up! Python calculates the answer, but if you don't save it, it's gone forever.

Need a Hint?
Just writing health + potion does the math, but doesn't update the variable. You need to use the = sign.
Output will appear here...
Exercise 3.3

The Bad Discount (Advanced)

A store wants to give a 20% discount on a $200 item. Use logic to figure out why this calculation is wrong.

Need a Hint?
Subtracting 0.20 from 200 just gives 199.8. You need to subtract (20% OF 200).
Output will appear here...

Capstone: The Travel Planner

Good programmers don't write 50 lines at once. They write 5, test, then write 5 more. Let's compare a "lazy" approach vs. a "structured" approach.

The Problem:

You are planning a 5-night trip to Paris. You have saved $1,000 USD.
You need to write a program to:

  1. Convert your dollars to Euros (rate: 0.85).
  2. Calculate the total cost of the hotel (100 Euros/night).
  3. Calculate the total cost of food (50 Euros/day).
  4. Subtract the expenses from your budget to see what's left.

Bad Practice

The "Lazy" One-Liner

This programmer hates typing. They use single-letter variables (`b`, `n`, `r`) and try to do all the math in one line.
The Bug: The calculation result is wrong. It implies they have more money after the trip than expected!

Need a Hint?
Check the math signs (+ vs -). Are they subtracting all the expenses?
Output will appear here...
Good Practice

The Structured Approach

This version breaks the problem into steps. We've started the code for you, but left the calculations blank.
Your Task: Replace the ?? with the correct math variables.

Output will appear here...