Answer to Question #80129 in Python for somnath khanra
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.
1
2018-08-27T04:43:49-0400
def isprime(n):
if (n == 0) or (n==1):
return False
elif (n == 2) or (n==3):
return True
elif (n % 2 == 0) or (n % 3 == 0):
return False
i=5
while i * i <= n:
if (n % i == 0) or (n % (i+2) == 0):
return False
i += 6
return True
def sumprimes(l):
prime_sum = 0
for elem in l:
if isprime(elem):
prime_sum += elem
return prime_sum
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
Python
Comments
Leave a comment