Question
nswer the following question without running the code. The procedure isMyNumber is used to hide a secret number (integer). It takes an integer x as
nswer the following question without running the code. The procedure isMyNumber is used to hide a secret number (integer). It takes an integer x as a parameter and compares it to the secret number. It returns:
-
-1 if the parameter x is less than the secret number
-
0 if the parameter x is correct
-
1 if the parameter x is greater than the secret number
The following procedure, jumpAndBackPedal, attempts to guess a secret number. The only way it can interact with the secret number is through the isMyNumber procedure explained above.
def jumpAndBackpedal(isMyNumber): ''' isMyNumber: Procedure that hides a secret number. It takes as a parameter one number and returns: * -1 if the number is less than the secret number * 0 if the number is equal to the secret number * 1 if the number is greater than the secret number returns: integer, the secret number ''' guess = 1 if isMyNumber(guess) == 1: return guess foundNumber = False while not foundNumber: sign = isMyNumber(guess) if sign == -1: guess *= 2 else: guess -= 1 return guess
*******Unfortunately, the implementation given does not correctly return the secret number. Please fix the errors in the code such that jumpAndBackpedal correctly returns the secret number.********
def jumpAndBackpedal(isMyNumber): ''' isMyNumber: Procedure that hides a secret number. It takes as a parameter one number and returns: * -1 if the number is less than the secret number * 0 if the number is equal to the secret number * 1 if the number is greater than the secret number returns: integer, the secret number ''' guess = 1 if isMyNumber(guess) == 1: return guess foundNumber = False while not foundNumber: sign = isMyNumber(guess) if sign == -1: guess *= 2 else: guess -= 1 return guess
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