A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 3 years 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
  1. anonymous
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It is a Python code.

  2. anonymous
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It 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))

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.