Python输出一百以内的质数(素数)

>>> p=[2,]
>>> for i in range(2,101):
for temp in range(2,i):
if i%temp==0:
break
if temp==i-1:
p.append(i)

>>> print(p)


[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]

猜你喜欢

转载自blog.csdn.net/dancria/article/details/78516106
今日推荐