gpt4 book ai didi

python - 为什么每次我尝试运行 Python 程序时 Eclipse 都会要求我输入 'ant build'?

转载 作者:行者123 更新时间:2023-11-28 19:25:59 26 4
gpt4 key购买 nike

我不熟悉编程和使用 pydev 在 eclipse 中运行我的 python。我正在使用 Eclipse EE 和 Python 2.7.3 我尝试运行的代码在这里:

def evaluate_poly(poly, x):

sumPoly = 0

for i in range(0,len(poly)):
#calculate each term and add to sum.
sumPoly = sumPoly+(poly[i]*x**i)
return sumPoly




def compute_deriv(poly):

derivTerm = ()

#create a new tuple by adding a new term each iteration, assign to derivTerm each time.
for i in range(0,len(poly)):
#i is the exponent, poly[i] is the coefficient,
#coefficient of the derivative is the product of the two.
derivTerm = derivTerm + (poly[i]*i,)
return derivTerm



def compute_root(poly, x_0, epsilon):

#define root to make code simpler.
root = evaluate_poly(poly,x_0)
iterations = 0

#until root (evaluate_poly) is within our error range of 0...
while (root > epsilon) or (root < -epsilon):
#...apply newton's method, calculate new root, and count iterations.
x_0 = (x_0 - ((root)/(evaluate_poly(compute_deriv(poly),x_0))))
root = evaluate_poly(poly,x_0)
iterations = iterations + 1
return (x_0,iterations)

print compute_root((4.0,3.0,2.0),0.1,0.0001)

每次我尝试运行此 eclipse 时都会要求我进行 ant 构建。当我单击确定时,没有任何反应。只有当我在函数内部运行函数时才会发生这种情况,看起来非常基本的代码不是问题。出了什么问题,我该如何解决?

最佳答案

如果你只有函数,python 不会做任何事情。它不会无缘无故地运行任意函数。如果你想打印一些东西,你需要调用你的函数之一。最好的方法是将其添加到代码的底部:

if __name__ == '__main__':
evaluate_poly([1, 2, 3], 4)

关于python - 为什么每次我尝试运行 Python 程序时 Eclipse 都会要求我输入 'ant build'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13094567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com