Is the Answer Right?
Exit

Is the Answer Right?

Use a comparison operator to check if the player's answer matches the correct one

💻

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

The quiz shows the player's answer number and the correct answer number side by side. But the player still has to compare them manually. PyQuiz should do that comparison and store the result so the program knows whether the answer was right.

Python's comparison operators compare two values and produce a Boolean — either True or False.

OperatorMeaning
==equal to
!=not equal to
>greater than
<less than
>=greater than or equal to
<=less than or equal to

For example:

temperature = 72
is_warm = temperature >= 70
print(is_warm)

True

The expression temperature >= 70 evaluates to True because 72 is greater than or equal to 70. That Boolean value is stored in is_warm.

A == comparison works the same way — it checks whether two values are exactly equal and produces True or False:

target = 5
guess = 3
matched = guess == target
print(matched)

False

Store the result of your comparison in a variable so you can use it later — to print feedback, drive other logic, or both.

Instructions

Add the comparison and update the result display.

  1. After answer = int(answer_text), create a variable named is_correct and assign it the result of comparing answer to correct using == — storing the result in a variable means you can act on it later with if/else to print "Correct!" or "Wrong!".
  2. Replace print(f"The correct answer is: {correct}") with print(f"Correct: {is_correct}") — this shows the Boolean result directly so you can verify the comparison is working before adding conditional logic.