用while循环求素数
想用while循环求100以内的所有素数,下面的代码哪里错了?list=[]
i = 2
while i < 100:
j = 2
while j <= i:
if i%j == 0:
break
j = j + 1
else:
list.append(i)
i = i + 1
print(list)
list=[]
i = 2
while i < 100:
j = 2
while j <= i:
if i%j == 0:
# break 不要break
j = j + 1
else:
list.append(i)
i = i + 1
print(list) break为什么要放在里了 list=[]
i = 2
while i < 100:
j = 2
while j < i:
if i%j == 0:
break
j = j+1
if j == i :
list.append(i)
i = i + 1
print(list)
页:
[1]