python求100以内的素数
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)
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)