Advertisement
Cloude

Untitled

Mar 4th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def odd_even_sums(tup):
  2. d = {}
  3. def odd_even_sum(tup):
  4. if len(tup) == 0:
  5. return tup + (0,0)
  6. elif len(tup) == 1:
  7. return tup + (0,)
  8. elif len(tup) == 2:
  9. return tup
  10. else:
  11. if tup in d:
  12. return d[tup]
  13. else:
  14. d[tup] = (tup[0] + odd_even_sum(tup[2:])[0], tup[1] + odd_even_sum(tup[2:])[1])
  15. return d[tup]
  16. if tup in d:
  17. return d[tup]
  18. else:
  19. d[tup] = odd_even_sum(tup)
  20. return d[tup]
  21.  
  22.  
  23.  
  24. a=1
  25. tup=()
  26. while (a<10):
  27. tup += (a,)
  28. a+=1
  29. print(tup)
  30. input()
  31. print(odd_even_sums(tup))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement