【发布时间】:2015-10-08 04:11:58
【问题描述】:
我知道有很多方法可以找到前 100 个素数,但请帮助我的方法。我发现count 的值正在增加,但由于某种原因while 循环条件不适用:
count = 0
while(count <= 20):
for i in range(2, 20):
for j in range(2, i):
if i < j:
print("The number",i,"is prime")
elif i % j == 0:
break
else:
print("The number",i,"is prime")
count = count + 1
print(count)
【问题讨论】:
-
如果您使用
3.x作为标签指示,__future__导入是多余的。 -
还有
while(count <= 20):一般写成while count <= 20: -
@JonSurrell:如果问题使现有答案无效,请不要更改问题。