Python 3 Program To Find The Sum of An Array

python 3 program to find the sum of array

In this tutorial, you will learn a simple Python program to find the sum of an array. To understand this Python program, you should have an understanding of the following concepts:

We can do this by 2 methods. First, we can calculate the sum of all the elements in the array without using functions. Secondly, we can create a function to add all the elements of an array and then print the sum by calling that function.

Recommended Read – 10 Best Books To Learn Python For Beginners And Experts.

Let’s see how we can do this by these 2 methods.

Python 3 Program To Find Sum of Array Without Function

Source Code:

Age = [10, 12, 13]       #Inputting Array values. 
theSum = 0               #Definig variable to store the sum of array. 
for i in Age:            #For loop to iterate through the array
 theSum = theSum + i     #Adding array elements. 

print(theSum)            #Outputting the sum of array elements.

Output

output of python program to find sum of array

Related postHow To Use ArcGIS API for Python and Jupyter Notebooks.

Python 3 Program To Find Sum of Array Using Function

Source code:

Age = [10, 12, 13]
def sumArray():
    addition = 0
    for i in Age:
        addition = addition + i
    print(addition)
sumArray()

Output

python program to find sum of array with function

Download the Jupyter PDF file.

Download from our Python GitHub repository.

Related Python 3 Programs

  1. Python 3 Program To Add Two Matrices.
  2. Python 3 Program to Check Armstrong Number.
  3. Python 3 Program to Find the Sum of Natural Numbers.
  4. Python 3 Program To Find The Factorial Of A Number.
  5. Python 3 Program to Find Largest Among Three Numbers.
  6. Python 3 Program to Check Leap Year.
  7. Python 3 Program To Check If Number Is Positive Or Negative.
  8. Python 3 Program To Convert Celsius To Fahrenheit.
  9. Python 3 Program To Find Largest Element In An Array.
  10. Python 3 Program to Convert Kilometres to Miles.

Scroll to Top