anonymous
  • anonymous
can anyone help me run this code properly? 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?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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
maitre_kaio
  • maitre_kaio
sqrtbi(9.0, 0.01): Bi method. Num. Interactios 11 Estimation 3.00146484375 And maybe I'm a little psychotic, but I say it one more time, please use a pastebin to make it easy for us to copy the code. And no need to start a new question, you'd better take into account the answers given to the other one.
anonymous
  • anonymous
1 Attachment

Looking for something else?

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

More answers

anonymous
  • anonymous
you got it dude
maitre_kaio
  • maitre_kaio
http://en.wikipedia.org/wiki/Pastebin Thx for the code, but because I'm a good guy, I reformatted it myself. And tested it too: sqrtbi(9.0, 0.00001) -> Bi method. Num. Interactios 21 Estimation 3.00000143051
maitre_kaio
  • maitre_kaio
lol i understand now... I reformatted your code too well sorry. If you look at the return statement, it is inside the while loop. It should be after the loop, like this: http://pastebin.com/8H6YW4Kn
anonymous
  • anonymous
haha THANK YOU!!!!!

Looking for something else?

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