Python Basics · Getting Started · lesson 5 of 12
Reading input
about 10 minutes · free · runs in your browser
Asking a question
input() pauses the program, waits for the person to type a line, and hands it back as
a string. Whatever you pass to input() is printed first as the prompt:
name = input("What is your name? ")
print(f"Hello, {name}!")
input() always returns a string. Even if they type 42, you get "42". To do
arithmetic you must convert:
age = int(input("How old are you? "))
In PyLearn the answers are supplied for you — this lesson feeds in Ada and then
36 — so your program runs the same way every time.
Your turn: ask for a name using the prompt Name: , then an age using the prompt
Age: , then print a line of the form Ada will be 37 next year.
Use those two prompts exactly, since the check compares the whole conversation.
You start from this, and edit it in the browser:
# Ask for a name, then an age, then print the sentence.