Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import random In the guess-the-number program discussed in this chapter, the computer thinks of a number and the user inputs guesses, until a correct guess

image text in transcribed

import random In the guess-the-number program discussed in this chapter, the computer thinks of a number and the user inputs guesses, until a correct guess is detected. Write a program in which these roles are reversed: the user thinks of a number and the computer computes and outputs guesses. Like the computer in the earlier version of this game, the user must provide hints, such as (meaning "my number is smaller" and "my number is larger," respectively), when the computer guesses incorrectly. The user inputs = when the computer guesses correctly. The user should input the lower bound and the upper bound of the range of numbers at startup. def main(): "*"Inputs the bounds of the range of numbers, and lets the user guess the computer's number until the guess is correct. ** smaller = int(input("Enter the smaller number: "); larger = int(input("Enter the larger number: "); myNumber = random.randint(smaller, larger), count = 0 while True: count += 1 user Number = int(input("Enter your guess: ")) if userNumber myNumber: print("Too large") else: print("You've got it in", count, "tries!") break The computer should need at most round(logz(high-low) + 1) guesses to get the correct number. Your program should track the number of guesses and output the message You're cheating! if the number of incorrect guesses reaches the maximum needed. When the program guesses correctly, output the message Hooray, I've got it in x tries!, where x is the number of tries. Here is a sample interaction with this program: 22 if __name__ == "_main__": main() 23 Enter the smaller number: 1 Enter the larger number: 100 Your number is 50 Enter =, > Your number is 75 Enter =, , or > := Hooray, I've got it in 4 tries

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

Students also viewed these Databases questions