0

i have a list of integers and i want to check which element is prime number and append that prime number in to another list. second 'for' loop does not work . how can i fix this issue?

a=[3,5,129,678,113,15,17]
b=[]
for i in a:
    c=0
    for a in (2,i//2):
        if i%a==0:
            c+=1
        if c==0 :
             b.append(i)
iman j
  • 21
  • 4
  • After you got your loops fixed, check out [this](https://stackoverflow.com/questions/3939660/sieve-of-eratosthenes-finding-primes-python) for more primes stuff – FObersteiner Aug 29 '19 at 20:19

1 Answers1

1

Change the indentation level of your second “if”. Instead of being on the same level as your first “if”, it should be on the same level as the inner “for”

Also, you might want to add a condition that your number = 2 you append it, since 2 is prime.

Mike
  • 1,471
  • 12
  • 17