def sqrt (n, one):
floating_point_precision = 10*16
n_float = float(( n * floating_point_precision) // one) / floating_point_precision
x = (int(floating_point_precision * math.sqrt(n_float)) * one) // floating_point_precision
n_one = n * one
while 1:
x_old = x
x = ( x + n_one // x) // 2
if x == x_old:
return x
print "The newton estimate of", mynum, "is", sqrt(mynum)
Traceback (most recent call last):
File "/Users/Brett/Desktop/Python/squareroot.py", line 21, in <module>
print "The newton estimate of", mynum, "is", sqrt(mynum)
TypeError: sqrt() takes exactly 2 arguments (1 given)
Tags:
您的}。然而,在最后一行中,您只传递了一个参数。在
sqrt()
函数接受两个参数,n
和{您的
sqrt
函数有两个参数,但您只提供了一个参数。第二个参数似乎应该是值“1”。在您已经将
sqrt
定义为接受两个参数的函数。稍后,您的代码引用您的函数:sqrt
。尝试将"/Users/Brett/Desktop/Python/squareroot.py", line 21
更改为使用math.sqrt
,或者为其提供第二个参数。在相关问题 更多 >
编程相关推荐