Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1secret = random.randint(1, 20) | Aif guess > secret: print("Too high!") | |
| 2while guess != secret: | BThe counter is reset to 0 on every turn of the loop, so it can never count up. It should start at 0 before the loop and add 1 inside it. | |
| 3Count each turn by adding 1 to the guesses counter inside the loop | CA single = assigns a value to a variable. To compare two values you need the double equals == operator. | |
| 4Give a hint when the guess is bigger than the secret number | DKeeps repeating the indented lines until the player's guess is equal to the secret number | |
| 5if guess = secret: print("Correct!") | EPicks a random whole number from 1 to 20 and stores it as the secret number the player must guess | |
| 6secret = random.randint(1, 20) while guess != secret: guesses = 0 | Fguesses = guesses + 1 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
while guess != secret: — The loop at the heart of a guessing game. It keeps asking until the guess matches the random secret number. If/elif/else gives hints and a counter adds 1 each turn.import random
secret = random.randint(1, 10)secret = 7
guess = 0
while guess != secret:while guess != secret:
guess = int(input("Guess: "))
count += 1if guess < secret:
print("Too low!")
elif guess > secret: print("Too high!")
else:
print("Correct!")