Course outline · 0% complete

0/32 lessons0%

Course overview →

Project: Number Guessing Game

lesson 10-1 · ~12 min · 30/32

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:

  1. Store the secret (we fix it at 47 so tests are repeatable).
  2. while True: to keep the game going (lesson 5-2).
  3. int(input()) to read each guess (lesson 3-2).
  4. An if/elif/else chain to compare (lesson 4-1).
  5. break on 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).