🐛 Debugging & Error Types

In Computer Science, a "Bug" is just an error that needs a solution!

1. Syntax Errors

The "Grammar" errors. This happens when you break the rules of the programming language (e.g., forgetting a colon or a bracket).

Syntax Error ❌ Program won't run
Example:
if age > 18 # Missing colon!
if age > 18:

2. Logic Errors

The "Brain" errors. The program runs perfectly, but the result is wrong because your formula or logic is incorrect.

Logic Error ⚠️ Runs, but gives wrong result
Example: Calculating an average of two numbers
avg = num1 + num2 / 2 # Math order is wrong!
avg = (num1 + num2) / 2

3. Runtime Errors

The "Crash" errors. Everything looks fine until the program is actually running and encounters a task it physically cannot do.

Runtime Error 💥 Program crashes while running
Example: Dividing by Zero
x = 10 / 0 # Computers cannot divide by zero!
Example: Wrong Data Type
age = "ten" + 5 # Cannot add text and numbers together!
💡 Pro Debugging Tip: Dry Running
To find Logic Errors, use a Trace Table. Manually write down the values of your variables on paper as you go through each line of code. This is called a "Dry Run" and is the best way to catch bugs before your user does!