anonymous
  • anonymous
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
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!
maitre_kaio
  • maitre_kaio
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.
anonymous
  • anonymous
copy paste to text editor, replace all ## to nothing :P
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

Looking for something else?

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

More answers

maitre_kaio
  • maitre_kaio
Thanks, but we still don't know what is the problem with this code. I tested it and it seems to produce good results.
anonymous
  • anonymous
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?

Looking for something else?

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