sosuh=[2,3]
a = 5
while(a < 100):
b = 2
while(b <= (a/b)):
if not(a%b): break
b = b + 1
if (b > a/b) :
sosuh.append(a)
a = a + 1
print(sosuh)
怎么样才能去掉break和if 只使用while
sosuh=[2,3]
a = 5
while(a < 100):
b = 2
while(b <= (a/b)):
if not(a%b): break
b = b + 1
if (b > a/b) :
sosuh.append(a)
a = a + 1
print(sosuh)
怎么样才能去掉break和if 只使用while
如果把 while 当成 if 使用是不是就可以了
i = 2
result = list(range(2,100))
while(i < 100):
flag = 1
j = i - 1
while(j > 1 and flag):
while(i % j == 0 and flag):
result.remove(i)
flag = 0
j -= 1
i += 1
print(result)