A community for students.
Here's the question you clicked on:
 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 nonnegitive, 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
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 nonnegitive, 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

maitre_kaio
 4 years ago
Best ResponseYou've already chosen the best response.0Please 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
 4 years ago
Best ResponseYou've already chosen the best response.0copy paste to text editor, replace all ## to nothing :P

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0def sqrtbi(x, z): assert x>=0, 'x must be nonnegitive, 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
 4 years ago
Best ResponseYou've already chosen the best response.0Thanks, but we still don't know what is the problem with this code. I tested it and it seems to produce good results.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0when 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?
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.