In: Computer Science
A prime number (or prime) is a natural number greater than 1 that has no posítive divisors other than 1 and itself. Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Code and output
Code for copying
def sum_prime(n):
sum1=0
for i in n:
count=0
if i>0:
for j in range(2,int(i/2)):
if i%j==0:
count+=1
if count==0:
sum1+=i
return sum1
n=list(map(int,input("enter the list: ").rstrip().split()))
print("The sum is {}".format(sum_prime(n)))
Code snippet
def sum_prime(n):
sum1=0
for i in n:
count=0
if i>0:
for j in range(2,int(i/2)):
if i%j==0:
count+=1
if count==0:
sum1+=i
return sum1
n=list(map(int,input("enter the list: ").rstrip().split()))
print("The sum is {}".format(sum_prime(n)))