Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Syamantak Group Title

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
  • one year ago

  • This Question is Closed
  1. Syamantak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It is a Python code.

    • one year ago
  2. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • one year ago
    • Attachments:

See more questions >>>

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.