Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

create a python program 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 )
no chat gpt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

Identify global safety and health issues.

Answered: 1 week ago