The dragon explains
int() turns text into a number
The dragon: input() always hands you text, even for a question like 'how old are you?'.
The dragon: int(some_text) converts digit-text into a real number, one you can add, multiply, or compare.
example.pyPython 3age_text = input("Age? ")age = int(age_text)print(age + 1)
The dragon: You can also wrap the whole input() call directly: int(input("...")) does the same thing in one step.
example.pyPython 3age = int(input("Age? "))The dragon: Without int(), Python treats the text like words — adding two of them GLUES them together instead of adding the numbers.
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
gold_text = input("Gold? ") and the player types 5. What is gold_text + gold_text?
question.pyPython 3gold_text = input("Gold? ")print(gold_text + gold_text)
- "55" — the two pieces of text stuck togetherCorrect
- 10 — Python adds them as numbers
Why: "55". Without int(), gold_text is text, not a number — and adding two pieces of text joins them end to end.
Question 2 of 2
What does int(input("...")) do, compared to plain input("...")?
- It converts whatever was typed into a real numberCorrect
- Nothing different — input() already returns a number if you type digits
Why: int() converts the text input() returns into a real number you can do math with. Without it, even '5' stays text.
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
Ask "How much gold? " and wrap the answer in int(...) so it becomes a real number, not just digits-as-text. Then print that number plus 10.
- +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.