Question: In this assignment you will write a Python program that plays the side of the guesser. Your program will ask the user for an initial

In this assignment you will write a Python program that plays the side of the guesser. Your program will ask the user for an initial search space by prompting for two integers giving the lower and upper limits respectively. If these two integers are out of order (i.e. low > high) it will continue to prompt for appropriate limits. (It is not necessary to recover from non-integer input at this stage.) Your program will then ask the user to think of a number in the given range. It will ask the user if the mystery number is Less than, Greater than or Equal to each guess. Subsequent guesses will depend on how the user answers these queries. If at some point the user acknowledges that the guess is equal to the mystery number, your program will state the number of guesses used. If at some point the current search space consists of just one number your program will stop guessing, announce the number and state the number of guesses used. If at some point the search space becomes empty, your program will state that the answers given by the user were inconsistent.

A typical session with the user is reproduced below.

In this assignment you will write a Python program that plays the

side of the guesser. Your program will ask the user for aninitial search space by prompting for two integers giving the lower and

This is what I have so far, but I can't seem to get it right, please help!!

print() print() print('Enter two numbers, low then high.') low = int(input('low = ')) high = int(input('high = ')) print() guesses=0 while low > high: print('Please enter the smaller followed by the larger number.') low = int(input('low = ')) high = int(input('high = ')) print() print('Think of a number in the range '+str(low)+' to '+str(high)+'.') print() if low == high: print('Your number is '+str(low)+'. I found it in '+str(guesses)+' guesses.')

if low CMPS 5P Introduction to Programming in Python Programming Assignment 5 In this assignment you will write a Python program that plays the other side of the guessing game you implemented in pa3. Your program will ask the user for an initial search space by prompting for two integers giving the lower and upper limits respectively. If these two integers are out of order (ie. low high it will continue to prompt for appropriate limits. is not necessary to recover from non-integer input at this stage.) Your program will then ask the user to think of a number in the given range. It will make a sequence of guesses that emulate the Binary Search algorithm discussed in class. See the example Binary Search.py posted on the class webpage.) It will ask the user if the mystery number is Less than, Greater than or Equal to each guess. Subsequent guesses will depend on how the user answers these queries. If at some point the user acknowledges that the guess is equal to the mystery number, your program will state the number of guesses used. If at some point the current search space consists o one number your program will stop guessing, announce the number and state the number of guesses used. If at some point the search space becomes empty, your program will state that the answers given by the user were inconsistent. Your program will be called Question-py. A typical session with the user is reproduced below. python Question .py Enter two numbers low then high 10 OW high 1 Pl ea3e ter th e smaller followed by the larger number OW high 3 Pl ease enter th e smaller followed by the larger number low high 10 Think of a number in the range 1 to 10 Is your number Less than Greater than or Equal to 5? Type 'L', 'G' or 'E' x Please type 'L', 'G' or 'E' y Please type 'L', 'G' or 'E' e her sn gueaa. I found your Observe how the user is prompted repeatedly if the limits are out of order. Notice also the blank lines that appear before and after user input. Your program will accept only the letters L, G, or E pper or lower case) as valid input, and continues to prompt if any other input is supplied. Two more sessions follow

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!