Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer the following question without running the code. The procedure isMyNumber is used to hide a secret number (integer). It takes an integer x as

Answer 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

=+ how might this lead to faster growth in productivity?

Answered: 1 week ago