Get the Player's Answer
Exit

Get the Player's Answer

Use input() to wait for the player to type their answer

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

The quiz prints the question and options, then exits immediately. The player never gets a chance to type anything. To make the quiz interactive, you need a way to pause the program and wait for input.

The input() function

input() pauses the program, displays a prompt, and waits for the player to press Enter. Whatever they type is returned as a string and stored in a variable.

For example, to ask for a city name:

city = input("Enter a city: ")
print(city)

The string you pass to input() is displayed as the prompt — it is not stored anywhere. The player's response is what gets stored.

The result is always a string. Even if the player types a number, Python stores it as text. You will handle that in the next chapter.

Where the input line goes

The player answers after seeing the options. The input() call belongs after the blank line that follows the option list.

Instructions

Add the input prompt after the options.

  1. After the blank print() that follows the option list, create a variable named answer_text and assign it input("Your answer (1-4): ") — this pauses the program and waits for the player to type their choice. Whatever they type is stored as a string in answer_text.

Next Chapter →