4.02
Completed
Converting User Input to Numbers Converting User Input to Numbers

Learn why input() returns text and how to convert user input with int() and float() before doing math.

Converting User Input to Numbers

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

Converting User Input to Numbers

User input may look like a number, but input() always returns text first. This Block connects that important detail with the practical solution: converting suitable input using int() or float() before using it in calculations.

You will inspect raw input with type(), see why text and numbers cannot always be mixed, and compare string concatenation with real arithmetic. Then you will convert whole-number input with int(), decimal input with float(), and use the converted values in small programs such as an age-in-months calculator and a price calculation.

What you will learn:

  • Understand why input() always returns a string
  • Recognize the difference between numeric-looking text and actual numbers
  • Convert whole-number text with int()
  • Convert decimal-number text with float()
  • Use converted input in arithmetic calculations
  • Choose the right conversion for ages, prices, temperatures, and similar values
  • Recognize when conversion fails because the entered text does not match the requested number type

By the end, you will understand the full input flow: collect text, convert it to the right number type, and then use it safely in your program.

> Start now 90 cards · about 7 min

Ready to practice this in the browser?

> Play now