1. 程式人生 > >Python輸出一百以內的質數(素數)

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]