Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5 6 # Can you guess the random integer between 1 and 20 (inclusive) in 4 trys? # Write a program that randomly chooses an
5 6 # Can you guess the random integer between 1 and 20 (inclusive) in 4 trys? # Write a program that randomly chooses an integer between 1 and 20 inclusive and then gives the user 4 chances to guess the hidden number. After each incorrect answer the computer should say that the guess was too high or too low. If the user does not guess the number after 4 trys, the computer should say: "You are out of guesses, you lose!" and then tell the user what the hidden number actually was. import random import math 11 x = math.floor(20*random.random()) + 1 print("X = " , x) print("Guess a number between 1 and 20: ") guess = float(input() if(guess == x) : print("You win! The number is" , x) else: # all additional code goes inside of this else statement! Why? #1 figure out if the guess is too high or too low and then let the user know guess too high or too low #2 let user make another guess #3 find out if the user won (is the guess correct?) #if yes then inform user that they are correct and have won and the game now ends #if no then repeat the steps! print("hi") # remove this "hi" statement from your code. It is only here because Python requires that there be some code inside of an else statement that you create and I wanted to give you a Skeleton that you could run (even though it doesn't behave as desired until you write the needed code!)
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