Check If Correct
Use an if statement to print "Correct!" when the player's answer is right
Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.
The quiz currently ends with print(f"Correct: {is_correct}"). When the player gets it right, the output is Correct: True — not exactly satisfying feedback.
You already have is_correct as a Boolean. Now you need to check it and print a real message.
The if statement in practice
if condition:
# runs when condition is TrueFor PyQuiz, the condition is is_correct. When it is True, print "Correct!":
if is_correct:
print("Correct!")The indented print only runs when the player answered correctly. When they are wrong, nothing prints yet — you will handle that in the next chapter.
Where this goes
Replace the print(f"Correct: {is_correct}") line with the if block. It goes in the same position, right after print(f"You answered: {answer}").
Instructions
Replace the raw Boolean output with real feedback.
- Remove
print(f"Correct: {is_correct}")and replace it with anifstatement: ifis_correctisTrue, callprint("Correct!")— this runs the feedback message only when the player got it right, instead of always printing the rawTrue/Falsevalue.
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)
is_correct = answer == correct
print()
print(f"You answered: {answer}")
# Step 1: Replace the line below with: if is_correct: print("Correct!")
print(f"Correct: {is_correct}")
Interactive Code Editor
Sign in to write and run code, track your progress, and unlock all chapters.
Sign In to Start Coding