为什么代码在Jupyter中有效而在Spyder中无效?

时间:2018-10-02 14:28:15

标签: python jupyter-notebook spyder

因此,我尝试在Jupyter和Spyder中运行此代码。它在Jupyter笔记本中为我提供了正确的输出,但显示为 TypeError:在Spyder中无法调用'str'对象。请解释为什么会这样。另外,我尝试在调用函数中编写 float(guess),但仍然无法正常工作。

x = 25
epsilon = 0.01
step = 0.1
guess = 0.0

while abs(guess**2-x) >= epsilon:
if guess <= x:
    guess += step
else:
    break

if abs(guess**2 - x) >= epsilon:
    print('failed')
else:
    print('succeeded: ' + str(guess))

0 个答案:

没有答案