Answer to Question #310867 in Python for Fe 2

Question #310867

Sum of prime numbers in the input



Input


2 4 5 6 7 3 8

1
Expert's answer
2022-03-15T02:57:40-0400
def isPrime(num):
    # define a flag variable
    flag = True
    
    # prime numbers are greater than 1
    if num > 1:
        # check for factors
        for i in range(2, num):
            if (num % i) == 0:
                # if factor is found, set flag to True
                flag = False
                # break out of loop
                break
    return flag        


inp = list(map(int,input().split()))
sum = 0


for x in inp:
  if isPrime(x):
      sum += int(x)


print(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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS