import sys
EPSILON = 1e-15
c = float(sys.argv[1])
t = c
while abs(t - c/t) > (EPSILON*t):
t = (c/t + t)/2.0
print(t)
在执行程序时,给出以下消息
Traceback (most recent call last):
File "C:\Users\Sama_User\Desktop\1.py", line 3, in <module>
c = float(sys.argv[1])
IndexError: list index out of range
答案 0 :(得分:0)
您要将参数传递给程序吗?检查错误的行c = float(sys.argv[1])
。您需要运行python 1.py arg1
之类的程序才能访问arg1