Skip to content

Commit 5048b45

Browse files
author
root
committed
git commit -m "Chapter5"
1 parent 56df899 commit 5048b45

2 files changed

Lines changed: 21 additions & 47 deletions

File tree

Chapter3.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

Pythonds/Chapter5.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#%%
2+
def listsum(numlist):
3+
theSum=0
4+
for i in range(len(numlist)):
5+
theSum+=numlist[i]
6+
7+
return theSum
8+
# %%
9+
print(listsum([1,3,5,7,9]))
10+
11+
12+
# %% Sum with recursion
13+
def listsum2(numlist):
14+
if len(numlist)==1:
15+
return numlist[0]
16+
else:
17+
return numlist[0]+listsum(numlist[1:])
18+
19+
# %%
20+
print(listsum2([1,3,5,7,9]))
21+
# %%

0 commit comments

Comments
 (0)