A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 one year ago
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
'''
Pls correct the code such that it only return the secret number
 one year ago
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 ''' Pls correct the code such that it only return the secret number

This Question is Closed

Syamantak
 one year ago
Best ResponseYou've already chosen the best response.0It is a Python code.

msmithhnova
 one year ago
Best ResponseYou've already chosen the best response.1It is not exactly clear what is intended here but here is some code that you should be able to adapt to do what you need. It tries to guess the number in num that is between 0 and 100. import random num = random.randrange(101) def secretNum(guess): if guess < num: return 1 elif guess == num: return 0 else: return 1 def jumpAndBackpedal(isMyNumber): min_guess = 0 max_guess = 100 done = False while not done: guess = (max_guess + min_guess) // 2 print(max_guess, min_guess, guess) res = isMyNumber(guess) if res == 1: min_guess = guess elif res == 1: max_guess = guess else: done = True return guess print("Secret Number was:", jumpAndBackpedal(secretNum))
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.