Show the Result
Display the player's answer and the correct answer after they submit
Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.
The player typed an answer and pressed Enter, but the quiz exits immediately. There is no acknowledgement of what they chose or what the right answer was. You need to show both so the player knows what happened.
A blank line separates the input prompt from the result — the same visual rhythm used elsewhere in the quiz. Then two lines tell the player what they submitted and what the correct option number is.
Note: at this point, the quiz cannot say "Correct!" or "Wrong!" — deciding that requires comparing two values with an operator, which you will do in Lesson 4. For now, you display the facts and let the player draw their own conclusion.
Instructions
Display the player's answer and the correct answer.
- After
answer = int(answer_text), add a blank line withprint()— this separates the input prompt from the results, matching the visual rhythm used throughout the quiz. - Add
print(f"You answered: {answer}")— this confirms to the player what choice they submitted. - Add
print(f"The correct answer is: {correct}")— this shows the right answer so the player can see whether they matched it.
question = "What is the type of the value 3.14?"
option_1 = "int"
option_2 = "str"
option_3 = "float"
option_4 = "bool"
correct = 3
print("=== Python Quiz ===")
print()
print(question)
print()
print(f" 1) {option_1}")
print(f" 2) {option_2}")
print(f" 3) {option_3}")
print(f" 4) {option_4}")
print()
answer_text = input("Your answer (1-4): ")
answer = int(answer_text)
# Step 1: Add blank line
# Step 2: Print the player's answer
# Step 3: Print the correct answer
Interactive Code Editor
Sign in to write and run code, track your progress, and unlock all chapters.
Sign In to Start Coding