Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Input

Numeric input

All topicsPractise exam questions
Knowledge organiser

Input

301.6b

Cast input to numbers.

What you need to know

Since input() always returns a string, you must cast it to int or float before doing maths. Wrap the input() call inside int() or float().

Key points

  • int(input("Age: ")) converts to integer in one line
  • float(input("Price: ")) for decimals
  • Without casting, + concatenates instead of adding
  • Invalid input (e.g. letters for int) causes ValueError

Code examples

Numeric input
python
age = int(input("Enter your age: "))
next_year = age + 1
print("Next year you will be", next_year)