The dragon explains
What happens if you forget int()
The dragon: You've seen int() convert text into a number. Now let's see what happens if you forget it.
The dragon: input() ALWAYS returns text. Try to add a number to it directly, and Python stops you.
example.pyPython 3health = input("Health? ")print(health + 10)
The dragon: Python raises a TypeError — something like "can only concatenate str (not int) to str". That error is Python's honest way of saying: this is still text, not a number.
The dragon: The fix is exactly what you already know: wrap it in int() before doing any math with it.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 2
health = input("Health? "), and the player types 50. What happens when you run print(health + 10)?
question.pyPython 3health = input("Health? ")print(health + 10)
- A TypeError — health is still text, not a numberCorrect
- It prints 60
Why: A TypeError. health holds text, even though the player typed digits — and Python refuses to add text and a number without you converting first.
Question 2 of 2
What actually fixes the crash from the last question?
- Wrapping health in int() before adding: int(health) + 10Correct
- Nothing — the crash means Python is broken
Why: int(health) + 10 fixes it — converting first turns health into a real number Python can add to.
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
This code asks "How much health? " and tries to add 10 to it — but it crashes with a TypeError. Run it once to see the real error, then fix it by converting the answer with int() before adding.
- +2
PracticeTwo more, on your own
This lesson is part of PRO.
PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.
Unlock this lesson with PROStuck three times? The game offers the answer — unasked.