这是代码:
import math as m
primeproduct = 5397346292805549782720214077673687806275517530364350655459511599582614290
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181]
def pseudoroot(n):
print(n)
for i in n:
if n[i] > m.sqrt(primeproduct):
return n[i-1] #greatest divisor below the root
psrprime = pseudoroot(primes)
运行此代码会出现以下错误:
Traceback (most recent call last):
File "so.py", line 11, in
print(pseudoroot(primes))
File "so.py", line 7, in pseudoroot
if n[i] > m.sqrt(primeproduct):
IndexError: list index out of range
对我来说,这真的没有任何意义,因为for循环中的i是列表中的给定索引,并且不应超出该列表的范围.