实在看不懂这个程序是怎么回事,它返回
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 37, 38, 41, 43, 44, 46, 47, 49]
帮助?
def primeTest(n):
if n < 2:
return False
if n == 2:
return True
for x in range(3, int(n ** 0.5 + 0.5), 2):
if n % x == 0:
return False
return True
def primeList(largestValue):
primes = []
for a in range(2, largestValue):
if primeTest(a) == True:
primes.append(a)
return primes
print(primeList(101))
我已经意识到这是第一个函数primeTest
,因为如果我输入print(primeTest(10))
它就会返回True
。