25 XP

48. Guess the number

Beginner input simulation

Write a program that judges a number-guessing game. It reads whole numbers, one per line:

  • The first line is the secret number.
  • Every line after it is a guess. For each guess, print Too low if it is smaller than the secret, Too high if it is bigger.
  • For the right guess, print Correct! You took N guesses., where N counts every guess, the right one included. When the first guess is right, print Correct! You took 1 guess. (one guess, not "guesses").
  • Stop after the right guess: there may be more lines, and they must not be read.

Compare the guesses as numbers: as text, "99" would count as bigger than "100".

Example 1

Input42 50 25 42
OutputToo high Too low Correct! You took 3 guesses.
Explanation50 is too high, 25 too low, then 42.

Example 2

Input7 7 3
OutputCorrect! You took 1 guess.
ExplanationRight first time; the 3 is never read.

Constraints

  • Every number is a whole number from 1 to 100, alone on its line.
  • One of the guesses is right, so the game always ends.
  • Print nothing else. A prompt inside input() is fine: the tests leave it out of the output.

Submit also runs 5 more tests you can't see.

Practises User Input (lesson 6).

Code
# Read the secret number from the first line.
# Then read guesses one at a time, saying "Too low" or
# "Too high", until the right one; count the guesses.