livepython.net

166. Python Program to Make a Random Number Guessing Game

Mediumrandom

Overview

In chapter 11 the secret number was always 42. Now it is random, and random.seed() keeps it testable.

Problem Statement

Read a seed on the first line and call random.seed() with it. Then pick the secret number with random.randint(1, 20).

The player has up to 5 guesses, one per line. For each guess, print:

  • Too low if the guess is smaller than the secret,
  • Too high if it is bigger,
  • Correct! Guesses: N if it is right, where N is how many guesses it took. Then stop: read no more guesses.

If all 5 guesses are wrong, print Out of guesses. The number was X after the fifth one. For example, the seed 1 picks the secret number 5:

Too high
Too low
Correct! Guesses: 3

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

A seed, then up to 5 guesses, one per line. Example:

1
10
3
5

Output

The output for that example:

Too high
Too low
Correct! Guesses: 3

The tests try 4 different inputs.

Learn this firstChapter 18 · Python random Module: randint, choice and shuffle
solution.py
# write your code here

EXPECTED OUTPUT

1Too high
2Too low
3Correct! Guesses: 3

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.