Loading...

Python Debugging

A program can finish and still be wrong. You find that kind of fault by writing the number you doubt. Twelve seats, nine taken. The free seats should be what is left. The first program subtracts the wrong way, and print writes the result. You do not install a package and you do not create a folder. Nothing here stops. The fault is the number on the screen.

the subtraction runs backwards

python
total = 12
taken = 9
free = taken - total
print(free)

The screen shows -3. That is a whole number, with a minus sign and no decimal point. print writes it, and the program finishes. None is not written. -3 is not a free-seat count you can use. It is nine minus twelve. The names say free, but the arithmetic takes the seats away from the people who already sat down. Reading that line is how you see the fault. You do not need a second tool.

the useful order

python
total = 12
taken = 9
free = total - taken
print(free)

The second program is separate. The same two numbers are there, and only the order changed. The screen shows 3. Twelve minus nine is three seats left. print writes that 3, and it is a whole number with no decimal point. The first program is not rewritten by the second. Run the first one again and the screen is still -3. The fix is the order inside free, not a new package and not a new folder.

The next page is describing a function. This page only shows a wrong number, then the same numbers in the useful order.

The number shows the fault

The first screen is -3, and that program finishes. The second screen is 3. Twelve seats, nine taken, three left when the order is useful. The next page is describing a function.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
5
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top