User Input
input() shows a prompt, waits for the user to type and returns what was typed as a string. Convert it with int() or float() when you need a number, and handle bad input with try and except.
Our examples cannot ask for input in the page, so the typed value is shown as a variable.
Example
# name = input("Your name: ") -> the user types Ada
name = "Ada"
print("Hello, " + name)
# age = int(input("Age: ")) -> the user types 30
age = int("30")
print("Next year you will be", age + 1)Result
Hello, Ada Next year you will be 31
Exercise
Read a line typed by the user.
name = ("Name: ")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.