Phase 3 - Level 1: Basic Recursion
Introduction to recursion - functions that call themselves.
10 programs · open one, then the next
Start with Print 1 to N Recursively- 01Print 1 to N RecursivelyIntermediatePrint one through n with recursive calls. Students trace a zero base case, pending calls, and why printing after the recursive call reverses the return order.Open example →pydef print_1_to_n(n): # Base case if n == 0: return
- 02Factorial Using RecursionIntermediateCalculate factorial through recursive multiplication in Python. Students trace zero factorial, a stopping condition, and pending products on the call stack.Open example →pydef factorial(n): # Base case if n == 0 or n == 1: return 1
- 03Print N to 1 RecursivelyIntermediatePrint n down to one with recursive Python calls. Students compare work before a recursive call with work after it and identify the zero stopping condition.Open example →pydef print_n_to_1(n): # Base case if n == 0: return
- 04Even Numbers 1-N RecursivelyIntermediatePrint even integers through n using recursion. Students trace a smaller call before a parity check and understand why odd limits still produce even output.Open example →pydef print_even(n): # Base case if n == 0: return
- 05Odd Numbers 1-N RecursivelyIntermediatePrint odd integers through n with a recursive Python function. Students follow the zero base case, upward return order, and a remainder-based output filter.Open example →pydef print_odd(n): # Base case if n == 0: return
- 06Sum of First N Natural Numbers RecursivelyIntermediateSum one through n using recursive Python returns. Students trace a zero base case and see how pending additions combine after the smallest call finishes.Open example →pydef sum_natural(n): # Base case if n == 0: return 0
- 07Power x^n RecursivelyIntermediateCompute an integer base raised to a nonnegative exponent recursively. Students follow return values and distinguish the title's mathematical notation from XOR.Open example →pydef power(x, n): # Base case if n == 0: return 1
- 08Nth Fibonacci RecursivelyIntermediateFind a Fibonacci value by its zero-based index using Python recursion. Students trace two base cases, branching calls, and repeated work in the call tree.Open example →pydef fibonacci(n): # Base cases if n == 0: return 0
- 09Fibonacci Series RecursivelyIntermediatePrint Fibonacci terms by repeatedly calling a recursive function. Students separate term count from index and examine the cost of repeated branching recursion.Open example →pydef fibonacci(n): if n == 0: return 0 if n == 1:
- 10Sum of Digits RecursivelyIntermediateAdd decimal digits recursively in Python. Students combine a last digit with a smaller magnitude, use abs for negatives, and trace the zero base case.Open example →pydef sum_digits(n): # Base case if n == 0: return 0