Quiz
Warm-up from lesson 5-2: inside a `while True:` loop, which statement is the only way out?
The game
The program knows a secret number. The player guesses. After each guess the program answers higher, lower, or correct!, and the game ends on a correct guess.
The plan, in pieces you already own:
- Store the secret (we fix it at 47 so tests are repeatable).
while True:to keep the game going (lesson 5-2).int(input())to read each guess (lesson 3-2).- An
if/elif/elsechain to compare (lesson 4-1). breakon the correct guess.
The stdin panel plays the part of the player, guessing 50, 40, 45, then 47.
Code exercise · python
Run the core game. Follow one guess through the loop by hand: 50 is greater than 47, so the chain answers `lower`.
Code exercise · python
Your turn: upgrade the game to count attempts. Add a `tries` counter (the count pattern from lesson 5-3) that increases on every guess, and make the winning line print `correct in 4 tries` instead of `correct!`.
Problem
In the finished game, the player's guesses are 30, then 60, then 47 with secret 47. What are the three lines printed? Answer with the three words/phrases separated by commas (the last one counts tries).