Another modify task, and it carries on where the previous one stopped. A guessing game that gives you one guess is over very quickly. This one keeps going until you win.
The editor starts with the original guessing game again, with the secret number fixed at 7. Either paste in your program from the previous exercise, or make those changes again first: the random secret number, and the easy and hard modes.
Extend the game so that:
Everything the previous exercise asked for still applies: the same two
questions, random.randint called once after the mode is chosen, and a range of
1 to 10 in easy mode and 1 to 100 in hard mode.
Some details, so that your game can be checked automatically:
Okay NAME, guess a number between 1 and HIGHEST:, is
printed once, before the first guess. It is not repeated for later
guesses.The two questions and the guess question, as before:
Hello, what's your name?
Which mode do you want to play, easy or hard?
Okay NAME, guess a number between 1 and HIGHEST:
Then one message per guess, ending with the congratulations, and finally, where
NUMBER is how many guesses the user took:
Number of guesses: NUMBER
These examples show what happens when the secret number is 6 in the first run and 31 in the second. Your program will pick different numbers when you run it yourself.
Input:
Priya
easy
2
9
6
Output:
Hello, what's your name?
Which mode do you want to play, easy or hard?
Okay Priya, guess a number between 1 and 10:
Your guess is too low
Your guess is too high
Congratulations! You guessed correctly.
Number of guesses: 3
Input:
Ben
hard
40
40
20
31
Output:
Hello, what's your name?
Which mode do you want to play, easy or hard?
Okay Ben, guess a number between 1 and 100:
Your guess is too high
Your guess is too high
Your guess is too low
Congratulations! You guessed correctly.
Number of guesses: 4
Ben guessed 40 twice, and both count.
The checks fix the random seed before your program runs, exactly as in the
previous exercise, so they know the secret number in advance and can type in
guesses that eventually hit it. That only works if your program calls
random.randint once, after the mode is known.
Ask each question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The questions are part of the output that is checked here, so their spelling,
capital letters and punctuation count.
Make sure that you check for the following things:
while loop, and its condition keeps it going for as long as
the guess is not the secret number (!=).input() for the guess is inside the loop, so that each repetition
reads a new guess.print of the number of guesses is not indented, so it runs once,
after the loop.