很抱歉,如果这很明显,但我对python编程很陌生,为什么这个程序不会生成素数列表,其中大部分似乎是素数,但有一些不是。< / p>
#!/usr/bin/env python
print ("Prime Numbers")
Number = 2
while True:
Test = 2
while Test < Number:
if Number % Test == 0:
Number = Number + 1
else:
Test = Test + 1
print (str(Number) + " is a prime number!")
Number = Number + 1
答案 0 :(得分:4)
此模板可帮助您找到素数:
if Number % Test == 0:
Number = Number + 1
Test = 2 # you'll need to reset Test here
else: