Write a function sumprimes(l) that takes as input a list of integers l and retuns the sum of all the prime numbers in l.
here are some examples to show how your function should work.
>>> sumprimes([3,3,1,13])
19
>>> sumprimes([2,4,6,9,11])
13
>>> sumprimes([-3,1,6])
0
Answers
Answered by
0
a=[1,3,13,5]
sum=0
for i in range(0,len(a)):
sum=sum+a[i]
print("prime sum=",sum)
it is coding in Python language for print sum of prime no.
with output
sum=0
for i in range(0,len(a)):
sum=sum+a[i]
print("prime sum=",sum)
it is coding in Python language for print sum of prime no.
with output
Attachments:
Answered by
0
Answer:
def sumprimes(n):
sum=0
if n == 1:
return False
if n == 2:
return True
for i in range(0,len(n)):
num=n[i]
if num>1:
pr=True
for j in range(2,int(num**0.5)+1):
if num%j == 0:
pr= False
break
if pr:
sum=sum+num
else:
sum=0
return sum
Explanation:
Similar questions
Social Sciences,
7 months ago
Math,
7 months ago
Social Sciences,
7 months ago
Political Science,
1 year ago
Math,
1 year ago