A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

i am on lecture six and using python 2.7.2 whats wrong with my copied code? ##def sqrtbi(x, z): ## assert x>=0, 'x must be non-negitive, not' + str(x) ## assert z > 0, 'espilon must be positive, not' + str(z) ## low = 0 ## high = max(x, 1.0) ## guess = (low + high)/2.0 ## ctr = 1 ## while abs(guess**2 - x) > z and ctr <= 100: ## #print 'low:', low, 'high:', high, 'guess:', guess ## if guess**2 < x: ## low = guess ## else: ## high = guess ## guess = (low + high)/2.0 ## ctr += 1 ## assert ctr <= 100, 'Ineration

  • This Question is Closed
  1. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Please give code that is easy to try ! This code is fully commented, and we have to reformat it. Plus it seems to be incomplete (end missing). Use a pastebin and try to ease the job of those wanting to help... And explain what is the problem with the code, according to you.

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

    copy paste to text editor, replace all ## to nothing :P

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

    def sqrtbi(x, z): assert x>=0, 'x must be non-negitive, not' + str(x) assert z > 0, 'espilon must be positive, not' + str(z) low = 0 high = max(x, 1.0) guess = (low + high)/2.0 ctr = 1 while abs(guess**2 - x) > z and ctr <= 100: #print 'low:', low, 'high:', high, 'guess:', guess if guess**2 < x: low = guess else: high = guess guess = (low + high)/2.0 ctr += 1 assert ctr <= 100, 'Ineration count exceeded' print 'Bi method. Num. Interactios', ctr, 'Estimation', guess return guess

  4. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, but we still don't know what is the problem with this code. I tested it and it seems to produce good results.

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

    when i test it, the code spits out obserd awnsers such as sqrtbi(9, 0.0001) = 2.25... instead of 3, how can i count on it to find the square root of any given number?

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

23

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