Den*_*nis 2 python compiler-errors
我试图用 python 编写一个程序来计算无穷级数
1/1^2 + 1/2^2 + 1/3^2 +1/4^2 +.....
我的代码如下:
n = 100
x = np.zeros([n])
x[0] = 0
for i in range(n):
x[i+1] = x[i] + 1/float((i+1)**2)
print x[99]
Run Code Online (Sandbox Code Playgroud)
当我尝试执行代码时,它返回如下内容:
索引错误:索引 100 超出轴 0 的范围,大小为 100
我想知道代码有什么问题。谢谢!:)