寻找素数Python

f87krz0w  于 2023-06-07  发布在  Python
关注(0)|答案(1)|浏览(140)

我正在编写脚本,它可以在0到X的特定范围内找到素数。它的工作部分,它追加2和删除偶数从列表中,但它不会超过3。

cis = int(input("xd: "))
list1 = []
list2 = []
num = 2
while (num in range(0,cis)):
    list1.append(num)
    num += 1
    continue

num2 = list1[0]

for i in list1:
    if list1[0] in list2:
        None
else:
    list2.append(list1[0])
if i % num2 == 0:
    list1.remove(i)
    continue
if all(a % num2 != 0 for a in list1):
    num2 += 1
    continue

print (list1)
print (list2)

谢谢你的帮助。

yfjy0ee7

yfjy0ee71#

print(f'{num} is prime' if(num:= input('enter number:'))and num.isnumeric()and not isinstance(eval(num),float)and not eval(num)in [0,1] and not [i for i in range(2,(eval(num)//2)+1)if eval(num)% i == 0] else f'{num} is not prime')

相关问题