题目:
使用集合的差集运算,求100以内的质数
代码:
s0 = {i for i in range(1, 101)}
s1 = set()
s1.add(1)
for i in range(2, 101):
for j in range(2, i):
if i % j == 0:
s1.add(i)
break
else:
continue
s = s0 - s1
print(s)