Skip to content

Instantly share code, notes, and snippets.

@elkym
Created November 25, 2020 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elkym/656525b8d25a4a213bd7ad5d037cf6d0 to your computer and use it in GitHub Desktop.
Save elkym/656525b8d25a4a213bd7ad5d037cf6d0 to your computer and use it in GitHub Desktop.
Recursive function-- takes a tuple of any size, totals the even and odd elements, and returns a (2-value) tuple of those totals.
l1 = (1,3,9,10,4,3,2,5,17,16,11)
def odd(num):
if num % 2 != 0:
return True
def addIt(t):
l = [0,0]
return addItR(t,l)
def addItR(t,l):
var = t[0]
print(var)
if len(t) > 1:
t = t[1:]
if not odd(var):
l[0] = l[0] + var
print(l)
else:
l[1] = l[1] + var
print(l)
if len(t) == 1:
return (l)
return addItR(t,l)
print(addIt(l1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment