Previous Lecture lect16

lect16, Mon 03/11

Recursive Functions and Final Exam Review

Slides PDF

############################################
# Linear Series using Recursion
#
def series(n):
    if n <= 0:
        return 0
    return (3*series(n-1) + 1)

print(series(5))

"""
############################################
# Reversing a String using Recursion
#
def revStr(s):
    if len(s) == 0:
        return s
    return revStr(s[1:]) + s[0]

print(revStr("I love UCSB!"))