How to find all prime numbers in a set of bounded values?

Asked

Viewed 50 times

0

How to find all prime numbers in a set of { 1..100 }?

PS: After finding certain numbers, I need store it in a result list (result = []).

lista = []
result = []
cont = 0

for i in range(1, 1001):
    lista.append(i)
for j in lista:
    for i in range(1, 1001):
        if j % i == 0:
            cont += 1
            if cont == 2:
                result.append(j)
                cont = 0
print(result)

1 answer

0

Error of indentation, try:

lista = []
result = []
cont = 0

for i in range(1, 1001):
    lista.append(i)
for j in lista:
    for i in range(1, 1001):
        if j % i == 0:
            cont += 1
    if cont == 2:
        result.append(j)
    cont = 0
print(result)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.