6.4.1 Anatomy of Recursion: Base Case & Recursive Step

Unit: Unit 6: Functions • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Recursive countdown demonstration
def countdown(n):
    # 1. Base Case: stops the recursion when n reaches 0
    if n == 0:
        print("Blast off!")
        return

    # 2. Recursive Step: action + recursive call with smaller problem (n - 1)
    print(f"T-minus {n}...")
    countdown(n - 1)

print("Starting countdown:")
countdown(3)
Open in Live Interactive Python Sandbox →