Guess the Number
Python
25 pts
Guess the Number
The secret number is 7. A player’s guesses are stored in a list (there is no input() in the editor):
guesses = [3, 9, 7, 5]
Use a while loop with an index to check the guesses one by one:
- If the guess is smaller than the secret, print
X is too low. - If it is bigger, print
X is too high. - If it is correct, set
found = True, print the message below and stop the loop withbreak.
Keep the number of guesses used in a variable called tries. Add an else to the loop that prints Out of guesses (it will not run with this data).
Expected output:
3 is too low 9 is too high 7 is correct! Found in 3 guesses.
Checklist
- Check the guesses one by one and set
foundwhen a guess is correct. - Count the guesses in
triesand stop the loop at the correct guess. - Print a message for each guess you check.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
