Converting User Input to Numbers
Learn why input() returns text and how to convert user input with int() and float() before doing math.
Sounds useful?
Jump into the interactive version.
No setup. No account. Just Python.
Converting User Input to Numbers
Learn why input() returns text and how to convert user input with int() and float() before doing math.
Jump into the interactive version.
No setup. No account. Just Python.
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:
input() always returns a stringint()float()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.
Ready to practice this in the browser?
> Play now