Python Program to find the sum of prime numbers in a list using the function
In this program, you will learn how to find the sum of prime numbers in a list using the function in Python.
list1 = [10, 11, 12, 13, 14, 15]
Example: How to find the sum of prime numbers in a list using the function in Python
def findPrime(list1):
s = 0
for num in list1:
i = 2
p = 1
while i <= num / 2:
if num % i == 0:
p = 0
break
i = i + 1
if p == 1:
s = s + num
return s
list1 = [10, 11, 12, 13, 14, 15]
s = findPrime(list1)
print("Sum of all prime numbers:", s)
Output:
Sum of all prime numbers: 24