In this short PA, you will write a modified version of the simple number guessing game that was the small PA last week.
You should name this program guess_the_number_v2.py
.
If you’d like, you can make a copy of your version of guess_the_number.py
from last week and name it guess_the_number_v2.py
and start from there.
You can probably re-use some of the code.
This number guessing game will require you to use several if-statements and two while-loops.
The program should start out by asking a user to enter a number that should be guessed (presumably guessed by a separate user). The number entered should be 1-100. The prompt should look like so, with the number typed in on the next line:
Enter number to be guessed between 1 and 100, inclusive:
The number entered here is what will be used as the target for the guessing game. Similar to the program from last week, your program should use if-statements to validate the input number. If it cannot be converted to an integer, then issue the below message:
N is not an acceptable value.
If it is not 1-100 inclusive, print the below message:
N is not 1-100, inclusive.
Just replace N
with the value/number that was entered by the user.
Instead of exiting after an invalid input value, your program should use a while-loop to repeatedly ask the user for another input. It should keep requesting the input until it gets a valid value, even if it takes many tries.
After the number is validated, the quizzing component can commence. The user who is guessing has potentially unlimited guesses. Thus, you’ll also want to use a while-loop for this. If the player guesses correctly, then a message like the one below should be printed out, and then the program should exit.
N is correct! Ending game.
If the guess is incorrect, then print either
N is incorrect. Guess again.
In both cases replace N
with the guess.
You do not need to validate that the input value is an integer and between 1-100 inclusive.
After the user makes a correct guess, print a summary of the format below, and then end the program.
You used 3 guesses to get the correct solution.
The correct number was 52.
Below is an exampe run of the program. There will be more on Gradescope.
Enter number to be guessed between 1 and 100, inclusive:
Enter guess 1:
10 is incorrect. Guess again.
Enter guess 2:
20 is incorrect. Guess again.
Enter guess 3:
30 is incorrect. Guess again.
Enter guess 4:
80 is incorrect. Guess again.
Enter guess 5:
50 is correct! Ending game.
You used 5 guesses to get the correct solution.
The correct number was 50.
You will need to use if-statements in several places in this PA.
You will also need to use two while loops. One for repeating the prompt for the number to guess, and the other to repeat the prompt for the guesses.
This PA is due on Wednesday, September 12th at 4:00pm. Turn in the program via Gradescope. You should try to make sure that all of the test cases pass before you turn it in. You can still submit without all of the cases passing, but that is not preferable.
This assignment PA is a simplified version of a PA used by other such as Allison Obourn, Marty Stepp, et al.