6.100L | Fall 2022 | Undergraduate

Introduction to CS and Programming using Python

Lecture 15: Recursion

Topics: Recursion: iteration vs. recursion, inductive reasoning

Lecture Notes

Lecture 15: Recursion

Lecture 15 Code

Readings

Ch 6.1

Finger Exercise Lecture 15

Implement the function that meets the specifications below:

def recur_power(base, exp):
    """
    base: int or float.
    exp: int >= 0

    Returns base to the power of exp using recursion.
    Hint: Base case is when exp = 0. Otherwise, in the recursive
    case you return base * base^(exp-1).
    """
    # Your code here  

# Examples:
print(recur_power(2,5)  # prints 32

6.100L Finger Exercises Lecture 15 Solutions

Course Info

Instructor
As Taught In
Fall 2022
Learning Resource Types
Lecture Videos
Lecture Notes
Problem Sets
Programming Assignments with Examples
Readings
Recitation Notes