Computer Science
posted by Ege
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.

cool
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 
Hervé
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
Respond to this Question
Similar Questions

Cont. English
Dimmesdale is not free since he does not live with his moral code, because he is concerned with society’s condemnation. He hides his secret of adultery, which is going against his moral code of honesty. Consequently, he is unable … 
Please helpalgebra!
Here's the question I'm having trouble with. Please walk me completely through the question and give me the answer so I can thoroughly understand it, so I can solve similar problems in the future. #1: Mary uses a secret code to write … 
computer science
Create a method called countZeros, which takes an integer array as an input parameter and returns the number of zero entries in the array 
programming
There are several types of room in a hotel. The HotelRoom Class of Previous Programming Problem was not specific regarding the type of room. Assume that a hotel has guest rooms and meeting rooms. Modify the HotelRoom class as follows: … 
English
1. He kept a secret. 2. He broke a secret 3. He let out a secret. 4. He gave away a secret. 5. He betrayed a secret. ================= What is the opposite of #1? 
programming
I have a general question. i was given a task to write a c code which gets an integer number as an input and prints the number of digits the number has. I have written a function that does it, but the problem is whenever the integer … 
Computer Science/Pseudo Code Python
Hi, I'm confused about an assignment. I'm not sure what to do and would like some help. An example: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Pseudo code: Prompt user … 
MathMeasure's & area
1. Find the area of a parallelogram with base b and height h. B=82cm H=16.6cm a.**1,361.2 cm^2 b.6,724 cm^2 c.137.78 cm^2 d.98.6 cm^2 2.Identify all the sets to which the number belongs. Choose from rational number, irrational number, … 
Java Computer Science
Say I write an application that prompts the user to enter an integer. If the user enters a double or string or anything, anything not an integer an error will appear. I'm having trouble writing code to combat this problem so I can … 
math
Which of these is a rational number A.)integer 150 B.)integer 441 C.)integer 200**** D.)integer 250