---
title: "How to Print Sum of Prime Numbers in Python"
description: "Here is a sample Python program that shows how to print the sum of Prime numbers"
url: https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/
date: 2023-06-05
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2023/06/pexels-photo-4476376.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["Sum of Prime Numbers"]
type: post
lang: en
---

# How to Print Sum of Prime Numbers in Python

Here is a way to print the sum of the prime numbers. The simplified logic helps you with your interviews and projects.

![Print Sum of Prime Numbers](https://i0.wp.com/srinimf.com/wp-content/uploads/2023/06/pexels-photo-6001389.jpeg?resize=1880%2C1253&ssl=1)*Photo by Sam Lion on Pexels.com*

Prime number logic divides the number by 2; if the remainder is zero, you can say it is a prime number. The same is applied in this program.

## The sum of prime numbers

```
import numpy as np

def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(np.sqrt(num)) + 1):
        if num % i == 0:
            return False
    return True

arr1 = np.array([5,10,17,23,30,47,50])
prime_list = np.array([])
prime_sum = 0

for num in arr1:
    if is_prime(num):
        prime_list = np.append(prime_list, num)
        prime_sum += num

print("prime list:", prime_list)
print("prime sum:", prime_sum)
```

Advertisements

> [How to get out of your comfort zone and start living ](https://www.betterup.com/blog/comfort-zone)

Here’s the output, which prints the prime number list and the sum of these.

```
prime list: [ 5. 17. 23. 47.]
prime sum: 92
```

References

> A helpful book [you need for](https://srinimf.com/2017/10/09/it-skills-that-may-need-for-future-jobs/) your practice is [Python Data Structures.](https://www.amazon.in/Data-Structures-Python-Harsh-Bhasin/dp/9355513305/?tag=srinimf-21)

Related[Optimizing Python Code: Techniques and Examples](https://srinimf.com/2024/09/15/optimizing-python-code-techniques-and-examples/)

Related

Related[5 Nice Ways to Convert String to Matrix: Python](https://srinimf.com/2024/05/31/5-nice-ways-to-convert-string-to-matrix-python/)

- [Essential PySpark Concepts to Review Before Your Brillio Interview](https://srinimf.com/2024/10/04/essential-pyspark-concepts-to-review-before-your-brillio-interview/)DateOctober 4, 2024
- [Python Interview Prep in 1 Hour: 12 Essential Coding Programs](https://srinimf.com/2025/09/10/python-interview-prep-in-1-hour-12-essential-coding-programs/)DateSeptember 10, 2025
- [How to Find Sum of Series in Python](https://srinimf.com/2021/11/22/how-to-find-sum-of-series-in-python/)DateNovember 22, 2021

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2023%2F06%2F05%2Fhow-to-print-sum-of-prime-numbers-in-python%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2023%2F06%2Fpexels-photo-4476376.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Print%20Sum%20of%20Prime%20Numbers%20in%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Print%20Sum%20of%20Prime%20Numbers%20in%20Python&body=https%3A%2F%2Fsrinimf.com%2F2023%2F06%2F05%2Fhow-to-print-sum-of-prime-numbers-in-python%2F&share=email)
-

### Like this:

Like Loading…
