Question: In this assignment, you are going to create a program that allows a user to try and guess a random number. In order to generate

In this assignment, you are going to create a program that allows a user to try and guess a random number.
In order to generate a random number, you are going to use the random library. Here is an example of how to do that. This will create a variable named "random_number" and the value will be some number between 0 and 100:
import random
random_number = random.randint(0,100)
In your program, create a function called "guess" that takes one parameter, the number to guess. Here is an example of how you might do that:
def guess( number_to_guess ):
Then in the function, use the input() function to ask the user to enter a number. Remember to use the int() built-in function to tell Python that what the user enters should be treated like an integer.
Then you will use conditional statements to determine whether the number the user entered is bigger than the number passed as a parameter, smaller than the number passed, or the same.
In each case, be sure to give the user feedback (using the print() function) about the number they entered.
If the number is too big or too small, be sure to call the guess function again. Remember, this is called "recursion". This will ask the user to enter a new number and it will be evaluated again. Refer back to Chapter 5.8 for the section on Recursion.
After the function is defined, you should call it, and pass it a random number. For example:
random_number = random.randint(0,100)
guess ( random_number )
Your program should meet the following requirements:
Use comments as necessary to communicate to me, the reader of the program
Use a consistent naming convention for your variables (preferably using under_scores)
Use a consistent indentation format (tabs vs spaces)
Use meaningful variable names

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 Databases Questions!