How to find of all the prime numbers in a list with Python

1 Answer

0 votes
import math
 
def is_prime(num):
    if num == 0:
        return 0
    if num == 1:
        return 0
    for p in range(2, int(round(math.sqrt(num))) + 1):
        if int(round(num % p)) == 0:
            return 0
    return 1


lst = [4, 8, 17, 5, 9, 22, 21, 13, 18, 99]

for i in range(len(lst)): 
    if is_prime(lst[i]):
        print(lst[i])



'''
run:

17
5
13

'''

 



answered Oct 19, 2019 by avibootz
...