Store the Options
Store each answer option in its own variable
Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.
The question is now in a variable, but the four answer options are still hardcoded in the print() calls. Like the question, they belong in variables — so you can reuse them and change them in one place.
Strings need quotes
When you assign a string variable, the value must be in quotes:
season = "autumn"The quotes are what make it a string. Without them, Python looks for a variable named autumn — which doesn't exist.
This matters for your options because they happen to look like Python keywords. "float" (with quotes) is the string "float" — just text. Without quotes, float is a Python built-in. Always use quotes when you mean the text.
Generic example
direction_1 = "north"
direction_2 = "south"
direction_3 = "east"
direction_4 = "west"You'll follow the same pattern for the quiz options.
Note: the print() statements still use hardcoded text for now. That changes in the next chapter — once you have the variables, you'll wire them into the display.
Instructions
Store the four answer options as variables — once they have names, the display can reference them instead of duplicating the text each time.
- Create a variable named
option_1and assign it the string"int". - Create a variable named
option_2and assign it the string"str". - Create a variable named
option_3and assign it the string"float". - Create a variable named
option_4and assign it the string"bool".
question = "What is the type of the value 3.14?"
# Step 1: Create option_1 through option_4
print("=== Python Quiz ===")
print()
print(question)
print()
print(" 1) int")
print(" 2) str")
print(" 3) float")
print(" 4) bool")
Interactive Code Editor
Sign in to write and run code, track your progress, and unlock all chapters.
Sign In to Start Coding