Skip to content

Commit a2bfc25

Browse files
Create A_Very_Big_Sum_#30.py
I contributed in cognizance-amrita#30
1 parent b975a21 commit a2bfc25

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

python/A_Very_Big_Sum_#30.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#find sum of elements in given array
2+
def _sum(arr):
3+
4+
# initialize a variable to store the sum while iterating through
5+
# the array later
6+
sum = 0
7+
8+
# iterate through the array and add each element to the sum variable
9+
# one at a time
10+
for i in arr:
11+
sum = sum + i
12+
13+
return(sum)
14+
15+
#Taking input of the size of the array
16+
n=int(input())
17+
18+
#creating an empty list
19+
arr = []
20+
21+
# iterating till the range
22+
for i in range(0, n):
23+
ele = int(input())
24+
arr.append(ele) # adding the element
25+
print("Array is", arr)
26+
ans = _sum(arr)
27+
28+
# display sum
29+
print('Sum of the array is ', ans)

0 commit comments

Comments
 (0)