Question: Guessing Have the computer generate a random number between 1 and 1 0 0 , then prompt the user to guess a number between 1

Guessing
Have the computer generate a random number between 1 and 100, then prompt the user to guess
a number between 1 and 100. Test that the users input is an integer within the range, if it isnt,
tell them that it is invalid and allow them to continue guessing. Compare the users number to
the computers number, if the users number is lower than the computers, tell them that it is too
low, if it is higher, tell them that it is too high. Repeat until the user guesses the correct value.
Keep count of the number of guesses and display it when the user wins (exclude invalid entries).
Example Output (user input is in italics):
- Guessing Game
Im thinking of a number. Make a guess (1-100):
50
Too low! Guess again (1-100):
75
Too low! Guess again (1-100):
-1
Invalid input should be within range 1-100.
Guess again (1-100):
a
Invalid input should be an integer.
Guess again (1-100):
95
Too high! Guess again (1-100):
90
Too high! Guess again (1-100):
80
Too low! Guess again (1-100):
85
Correct! You got it in 6 tries.
Notes:
1. Place your name, date, and a brief description of the program in a comment block at the
top of your program. Place brief comments in your program to describe sections of code
(you should not have a comment describing every single line).
2. Your code should be placed in a main function.
3. Use the check_input module provided on Canvas to check the users input for invalid
values. Add the .py file to your project folder to use the functions. Examples using the
module is provided in a reference document on Canvas.
4. Use the random module to generate your random numbers. Examples for generating
random numbers is provided in a reference document on Canvas.
5. No need to create extra functions or add lists to your code, youll only need the main
function with a while loop and some if statements.
6. Please read through the Coding Standards reference document on Canvas for guidelines
on how to name your variables and to format your program.
7. Thoroughly test your program before submitting/demoing.
a. Make sure the program only creates the random number once at the beginning of
the program (not repeatedly changing the number as the user is guessing).
b. Make sure the program accurately responds to high/low/correct guesses.
c. Invalid guesses should not output Too high or Too low.
d. Make sure the program accurately reports the number of guesses the user made.
Count all valid guesses, including the final guess. Do not count any invalid
guesses (ex.0, negative numbers, or values greater than 100, or any strings).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!