The input() function always returns a string. If you want to perform arithmetic on the user’s input, you must convert it to a number first.

Integers: int(input(...))

To read a whole number from the user, wrap input() inside int():

age = int(input("Enter your age: "))
print("In 10 years you will be", age + 10)

This converts the string entered by the user (e.g., "14") into the integer 14, so you can do arithmetic with it.

Decimals: float(input(...))

To read a decimal number, use float() instead:

distance = float(input("Enter the distance in km: "))
time = float(input("Enter the time in hours: "))
speed = distance / time
print("Your speed is", speed, "km/h")

Common Pattern

The general pattern for reading numbers is:

# For whole numbers
variable = int(input("prompt"))

# For decimal numbers
variable = float(input("prompt"))

What Happens Without Conversion?

If you forget to convert, arithmetic will fail or produce unexpected results:

num1 = input("Enter a number: ")   # e.g., user types "5"
num2 = input("Enter a number: ")   # e.g., user types "3"
print(num1 + num2)                  # prints "53" (string concatenation!)

With conversion:

num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
print(num1 + num2)                  # prints 8 (arithmetic addition)