Python - 5

Python - 5: Getting User Input

Programs can ask users questions with input(). The answer is stored in a variable so your program can use it.

Your challenge: Ask the user for their name and favorite color, then use both answers in printed messages.

✦ Python Editor
▶ Output

Ask a question

Use: name = input("What is your name? ")

Python shows the question and stores the answer in name.

Use the answer

Because the answer is stored in a variable, you can use it in another message: print("Hello " + name)

Try it: Ask another question about a favorite food, hobby, or animal.

Good Python habit: Give input variables clear names so it is easy to remember what each answer contains.

👀 Show Example Solution
name = input("What is your name? ")

print("Hello " + name)

favorite_color = input("What is your favorite color? ")

print("Your favorite color is " + favorite_color)

Each input() question returns text, and that text is stored in a variable for the program to use.