求100以内的素数,并用逗号隔开
list1 = []
for i in range(2, 101):
for j in range(2, i):
if i % j == 0:
break
else:
list1.append(i)
print('100以内的素数有:', list1)
输出:
100以内的素数有: [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]