【发布时间】:2014-10-26 19:22:03
【问题描述】:
我正在学习 python,但是这段代码总是让我的文本编辑器崩溃。
谁能告诉我我做错了什么?
x = 12
epsilon = 0.01
numGuesses = 0
low = 0.0
high = max(1.0, x)
ans = (high + low)/2.0
while abs (ans**2 - x) >= epsilon:
print 'low =', low, 'high =', high, 'ans =', 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
有什么建议吗?
【问题讨论】:
-
high = ans 而不是 high-ans
-
这段代码肯定与编辑器崩溃无关。如果是,这将是题外话,属于 superuser.com
标签: python macos sublimetext2