Created
November 25, 2020 20:27
-
-
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.
This file contains 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
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