Fixing a Python TypeError from input() and Text Addition

Text plus a number is a real Python crash — and the error tells you exactly what went wrong.

  • Lesson 3 of 5
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

What happens if you forget int()

  1. The dragon: You've seen int() convert text into a number. Now let's see what happens if you forget it.

  2. The dragon: input() ALWAYS returns text. Try to add a number to it directly, and Python stops you.

    example.pyPython 3
    health = input("Health? ")print(health + 10)
  3. 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.

  4. 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.

  1. Question 1 of 2

    health = input("Health? "), and the player types 50. What happens when you run print(health + 10)?

    question.pyPython 3
    health = 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.

  2. 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. 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. +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 PRO

Stuck three times? The game offers the answer — unasked.