Welcome folks today in this blog post we will be calculating the sum of array
using the built in function sum()
in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Python 3 code to find sum # of elements in given array # driver function arr = [] # input values to list arr = [12, 3, 4, 15] # sum() is an inbuilt function in python that adds # all the elements in list,set and tuples and returns # the value ans = sum(arr) # display sum print ('Sum of the array is ',ans) # This code is contributed by Dhananjay Patil |
Now if you execute the above script by typing the below command
python app.py