Concept
The input() Trap
`input()` always returns text (a string), even if the user types numbers:
python
age = input("Age: ") # User types 20, Python sees "20"
next_year = age + 1 # CRASH! TypeError: can only concatenate str to str
# 11. The input() Trap `input()` always returns text (a string), even if the user types numbers: ```python age = input("Age: ") # User types 20, Python sees "20" next_year = age + 1 # CRASH! TypeError: can only concatenate str to str ``` You can't do math on text. Wrap it with `int()`: `age = int(input("Age: "))`.
Checkpoint
If a user enters `50` into `val = input()`, what is `val`?
Practice
Ask the user for their favorite number with `input()`, convert it using `int()`, and print double that number (`number * 2`).
01
Tap code blocks below to assemble
Available Blocks