Python Program to find the sum of all prime numbers in an array
In this program, you will learn how to find the sum of all prime numbers in an array in Python.
a = arr.array('i', [2, 3, 4, 5])
Example: How to find the sum of all prime numbers in an array in Python
import array as arr
a = arr.array('i', [2, 3, 4, 5])
s = 0
for i in a:
num = i
j = 2
f = 1
while j < num:
if num % j == 0:
f = 0
break
j = j + 1
if f == 1:
s = s + num
print("Sum of all prime numbers are : ", s)
Output:
Sum of all prime numbers are : 10