x = 12345.0 epsilon = 0.01 numGuesses = 0 low = 0.0 high = x ans = (high + low)/2.0 while abs(ans**2 - x) >=epsilon and ans <= x: #print low, high, ans numGuesses += 1 if ans**2 < x: low = ans else: high = ans ans = (high + low)/(2.0) #print 'numGuesses =', numGuesses print (ans), ('is close to square root of'), x why this code didn't run
Try without the # , because its taking the line, as a comment, also, check the identation, improve the python enhancement proposal, and i think that this line: #print 'numGuesses =', numGuesses its taking some variable more, i repeat, more than an string value, please specify what language and IDE are you using. PD: i'm taking this as a python code, for his similarity.
@gabrielcho I think they are using Python, since that is what the class uses. However, it would help to know which version of python they are using. And no matter which, that last line looks odd: `print (ans), ('is close to square root of'), x` would be: `print (ans, 'is close to square root of', x)` in 3.x And something else in most of 2.x
Join our real-time social learning platform and learn together with your friends!