From 1cfa1ca1da48c8be15adc0cef66fbd304b2c5deb Mon Sep 17 00:00:00 2001 From: Ishaan <39641326+ishaanbedi@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:37:22 +0530 Subject: [PATCH] Create array_sum.py --- array_sum.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 array_sum.py diff --git a/array_sum.py b/array_sum.py new file mode 100644 index 0000000..7c29fb9 --- /dev/null +++ b/array_sum.py @@ -0,0 +1,14 @@ +#calculate and return sum of all elements of a list +def sumList(p,sum = 0): + le = len(p) + if le==0: + return sum + else: + sum = sum+p[le-1] + p.pop() + return sumList(p,sum) + + +l = eval(input("Enter the list: ")) +p = sumList(l) +print(p)