In this short PA, you will write a simple number guessing game.
This number guessing game will require you to use several if-statements.
Name your program guess_the_number.py
.
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 10-100. The prompt should look like so, with the number typed in on the next line:
Enter number to be guessed between 10 and 100, inclusive:
The number entered here is what will be used as the target for the guessing game. You program should use an if-statement to validate the input number. You may assume that the input entered will only contain digits between 0-9. If it is not 10-100 inclusive, print the below message and then exit:
N is not 10-100, inclusive.
Just replace N
with the value/number that was entered by the user.
After the number is validated, the quizzing component can commence.
The user who is guessing only has two guesses.
On each guess, 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 wrong, then print N is incorrect.
.
In both cases replace N
with the guess.
If the user uses all of their (2) guesses without getting the answer correct, then the program should print out a summary, which displays the user’s guesses and the answer itself. Below is one example of this summary:
You did not guess the number within 2 attempts.
The target number was 47
Your guesses were 10 and 54
You should also include a comment at the top of the code file. The comment should include your name and a short description of what the program does. Below is a template you may use:
###
### Author: Your Name Here
### Description: Describe your program with one
### or more sentences of text.
###
You should also make sure to follow other good style principles, such as naming variables well writing having well-formatted and easy-to-read code. Part of the grade for the PA will be for code design and style.
Below are several examples of program runs. There will be more on Gradescope.
Enter number to be guessed between 10 and 100, inclusive:
47
First guess:
10
10 is incorrect.
Second guess:
54
54 is incorrect.
You did not guess the number within 2 attempts.
The target number was 47
Your guesses were 10 and 54
Enter number to be guessed between 10 and 100, inclusive:
75
First guess:
25
25 is incorrect.
Second guess:
75
75 is correct! Ending game.
You will need to use if-statements in several places in this PA.
This PA is due on Saturday, Jan 26th at 7: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.