Answer to Question #328129 in Python for Arun Kumar

Question #328129

Sum of prime numbers in the input

1
Expert's answer
2022-04-13T07:33:17-0400
#read a single line containing space-separated integer
numbersStr=input("").split(' ')
sumPN=0
for number in numbersStr:
    number=int(number)
    is_prime=True
    if number > 1:
        for i in range(2, number):
            if (number % i) == 0:
                is_prime=False
                break
        if is_prime:
            #calculate the sum of all prime numbers from 1 to N.
            sumPN=sumPN+number


#Display the result
print(str(sumPN))

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