Computer Science

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.

  1. 👍 0
  2. 👎 0
  3. 👁 1,122
  1. 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
    foundNumber = False
    while not foundNumber:
    sign = isMyNumber(guess)
    if sign == -1:
    guess *= 2
    elif sign == 1:
    guess -= 1
    elif sign == 0:
    foundNumber =True
    return guess

    1. 👍 0
    2. 👎 0
  2. 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
    '''
    if isMyNumber(0) == 1:
    return 0
    guess = 1;
    foundNumber = False
    while not foundNumber:
    sign = isMyNumber(guess)
    if sign == -1:
    guess *= 2
    elif sign == 1:
    guess -= 1
    else:
    foundNumber = True;
    return guess

    1. 👍 0
    2. 👎 0

Respond to this Question

First Name

Your Response

Similar Questions

  1. Ed Tech

    What does the code of conduct include? A. A secret code for internet users B. The conduct that should be used with a code C. A set of rules for behavior when using the internet D. A rule that tells you the code I think C Thanks!

  2. World History

    Which best describes laws developed by the Roman Empire? a) Hammurabi’s Code was displayed at the Roman Theatre of Merida. b) The Law of the Twelve Tables code was displayed at the Roman Forum. c) The Code of the Assura laws

  3. Science

    Which of the following would have less momentum than a 52 kg cheetah running at 10 m/s? A. A 71 kg lion running at 10 m/s. B. A 45 kg zebra running at 13 m/s. C. A 5,000 kg elephant walking at 1 m/s. D. A 61 kg zebra running at

  4. Science HELP!

    2:What is the genetic code? A:The order of amino acids in proteins makes up the genetic code. B:The order of amino acids in mRNA makes up the genetic code. C:The order of nitrogen bases in tRNA makes up the genetic code. D:The

  1. math

    a lock has a code of 5 numbers between 1 and 20 . If no numbers in the code are allowed to repeat, how many different codes could be made? so it is not 20C5 so can you tell me exactly what the answer is? I can try to figure out

  2. biology

    What can be said about mitochondria and its genetic code? Select all that apply. Mitochondria are unable to synthesize proteins using their genetic code. Mitochondrial proteins are made up of entirely different amino acids. The

  3. Computer Literary

    Which of the following is Not an example of debugging A)Looking for errors in programming code B)Fixing misspelled commands in programming code C)Solving faulty logic in programming code D)Upgrading to improve the programming code

  4. Medical Billing and Coding

    This 19-year-old college student was brought tot he ER and admitted with high fever, stiff neck, chest pain, cough, and nausea. A lumbar puncture was performed, and results were positive for meningitis. Chest x-ray revealed

  1. medical coder

    location inpatient hospital patient russell shergrud attending physician gregory dawson,md preprocedured diagnosis acute respiratory failure postprocedure diagnosis acute respiratory failure procedure performed intubation with a

  2. Science

    What is the genetic code? A. The order of amino acids in proteins makes up the genetic code. B. The order of amino acids in mRNA makes up the genetic code. C. The order of nitrogen bases in tRNA make up the genetic code. D. The

  3. chem grade 11

    okay so i have to prepare a procedure for the following experiment, except i have no clue what to do question- the science department had 5 different solutions but accidently lost thier labels. devise a procedure to help you

  4. History

    The Code Talkers were members of which Native American tribe? Apache Hopi Navajo******** Pueblo 2. Why was the Code Talkers' code so hard to break? It was based on a language that lacked an alphabet and was hard to learn. The

You can view more similar questions or ask a new question.