The Correct Answer
Exit

The Correct Answer

Store the correct option number in a variable

💻

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

The quiz displays a question and four options, but it has no record of which option is right. When the player answers, there is nothing to compare against. You need a variable that holds the correct answer.

Integers hold whole numbers

You've been working with strings so far. Integers store whole numbers — no quotes:

num_players = 4

The difference matters. "4" (with quotes) is a string — the text "4". 4 (no quotes) is an integer — a number. You will compare the player's answer to correct later, so it needs to be an integer.

Storing the correct option

For this question, option 3 ("float") is the right answer. Store that as an integer:

winner = 2

Once the player submits their answer, you will compare it to this value to determine whether they got it right.

Instructions

Add the correct answer variable.

  1. After the option_4 variable, create a variable named correct and assign it the integer 3 — this records which option is right so the quiz can compare the player's answer against it later.