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 lowif the guess is smaller than the secret,Too highif it is bigger,Correct! Guesses: Nif 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.