1

I am making script , that finds prime numbers in specific range from 0 to X. Its works partially , it appends 2 and remove even numbers from list , but it doesnt go over 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)

Thanks for help.

  • that `num += 1` does not do anything, because the `num in range` overwrites the values, it does not increment – njzk2 Dec 23 '16 at 17:38
  • 2
    also, fix your indentation – njzk2 Dec 23 '16 at 17:38
  • there are many similar questions here; [this](https://stackoverflow.com/questions/31120986/optimize-sieve-of-eratosthenes-further) is one of them. there are many others... – hiro protagonist Dec 23 '16 at 17:58
  • Problem is with dividing numbers by num2 , because for some reason script does not add 1 to num2 when there arent any even numbers in list1 – Já Prostě Já Dec 23 '16 at 18:17

1 Answers1

0

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')

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – LinFelix Jun 05 '23 at 11:52