Last active
October 16, 2015 19:39
-
-
Save svalleru/f468a96906dd98e55233 to your computer and use it in GitHub Desktop.
RecursiveSum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Calculate sum of the elements in a list 'recirsively' | |
def listsum(numList): | |
if len(numList) == 1: | |
return numList[0] | |
else: | |
return numList[0] + listsum(numList[1:]) | |
print(listsum([1,3,5,7,9])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment