This Python User Input lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
input reads a line from the keyboard and returns a string. Convert it with int or float when you need a number.
This page’s Run button does not prompt the keyboard. Pass the value as a variable, which is also how you test input code.
Example 1: Start here
On your machine, replace the quoted 82 with input(\"Score: \").
typed = "82" # text
score = int(typed) # text read as a whole number
print(score + 1)
Example 2: A stand-in for input
The browser runner cannot ask a question. Store the answer in a variable and the rest of the program stays the same.
answer = "Chennai" # text
print("City:", answer) # a comma prints each value, with a space between
Example 3: Turn the answer into a number
input returns text. int converts it when you expect a number.
answer = "24" # text
seats = int(answer) # text read as a whole number
print(seats + 1)
Example 4: The real call on your computer
input shows a prompt and waits. Use it in a local file, not in this browser runner.
print("On your computer: city = input('City: ')") # print writes this; the quotes are not shown
