Skip to content

Commit c71e4e5

Browse files
authored
Create sum_of_elements_of_an_array.py
1 parent da80a61 commit c71e4e5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

sum_of_elements_of_an_array.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
list1 = []
2+
i = 0
3+
a = 0
4+
print("Input numbers and enter 'end' to stop inputing")
5+
while i < 1:
6+
x = input()
7+
if x == "end":
8+
break
9+
elif x.isdigit():
10+
list1.append(int(x))
11+
else:
12+
print("INVALID INPUT")
13+
print("array is:", list1)
14+
15+
for i in range(0, len(list1)):
16+
a += list1[i]
17+
18+
print("Sum of all the elements of the array is:",a)

0 commit comments

Comments
 (0)