lis = [] for i in range(2,101): j = 2 while j < i: if i % j == 0: break j += 1 # i % j == 0为假,j = j+1,然后在比较j < i,相当于else: j += 1 else: lis.append(i) print('素数有:',lis)
本文共 268 字,大约阅读时间需要 1 分钟。
lis = [] for i in range(2,101): j = 2 while j < i: if i % j == 0: break j += 1 # i % j == 0为假,j = j+1,然后在比较j < i,相当于else: j += 1 else: lis.append(i) print('素数有:',lis)
转载于:https://www.cnblogs.com/laosun0204/p/8676383.html