Answered step by step
Verified Expert Solution
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 "randomnumber" and the value will be some number between and :
import random
randomnumber random.randint
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 numbertoguess :
Then in the function, use the input function to ask the user to enter a number. Remember to use the int builtin 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 for the section on Recursion.
After the function is defined, you should call it and pass it a random number. For example:
randomnumber random.randint
guess randomnumber
no chat gpt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started