有一个带有质数的代码(显示在所需范围内)
代码如下:
a, b = map(int, input().split())
ls = []
for i in range(a, b + 1):
if all(i % n != 0 for n in range(2, i)):
ls.append(str(i))
if len(ls):
print(' '.join(ls))
else:
print(0)
答案 0 :(得分:0)
我认为您需要循环打印结果
print('= Enter the range (a,b) =')
a, b = map(int, input().split())
ls = []
for i in range(a, b + 1):
if all(i % n != 0 for n in range(2, i)): # check the numbers
ls.append(str(i))
print('========= Result ========')
#print the result
for number in ls:
print(number)
print('========== End ==========')