Lab 13, Part 0: Fruitful recursion warm-up

Part 0

def sumUpTo(num):
    if num > 0:
         return num + sumUpTo(num-1)

Part 1

In []: grabFirst([ ])
Out[]: [ ]
In []: grabFirst(['jen','rachel','faith'])
Out[]: ['j','r','f']
In []: grabFirst(['emma','sarah','abigail','bianca']
Out[]: ['e','s','a','b']

Part 2 countDivides


countDivides(100) returns 7

100
50.0
25.0
12.5
6.25
3.125
1.5625
0.78125

--
countDivides(17) returns 5

17
8.5
4.25
2.125
1.0625
0.53125

--
countDivides(8) returns 3

8
4.0
2.0
1.0

--
countDivides(2) returns 1
--
countDivides(1) returns 0
--
countDivides(0.5) returns 0
--
countDivides(0) returns 0
--

Table of Contents