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 numbers from 1 to n using recursion.Open example →pydef print_1_to_n(n): # Base case if n == 0: return
- 02Factorial Using RecursionIntermediateCalculate factorial recursively.Open example →pydef factorial(n): # Base case if n == 0 or n == 1: return 1
- 03Print N to 1 RecursivelyIntermediatePrint numbers from n to 1 using recursion.Open example →pydef print_n_to_1(n): # Base case if n == 0: return
- 04Even Numbers 1-N RecursivelyIntermediatePrint even numbers from 1 to n recursively.Open example →pydef print_even(n): # Base case if n == 0: return
- 05Odd Numbers 1-N RecursivelyIntermediatePrint odd numbers from 1 to n recursively.Open example →pydef print_odd(n): # Base case if n == 0: return
- 06Sum of First N Natural Numbers RecursivelyIntermediateCalculate sum of first n natural numbers recursively.Open example →pydef sum_natural(n): # Base case if n == 0: return 0
- 07Power x^n RecursivelyIntermediateCalculate x raised to power n recursively.Open example →pydef power(x, n): # Base case if n == 0: return 1
- 08Nth Fibonacci RecursivelyIntermediateFind nth Fibonacci number recursively.Open example →pydef fibonacci(n): # Base cases if n == 0: return 0
- 09Fibonacci Series RecursivelyIntermediatePrint Fibonacci series up to n terms recursively.Open example →pydef fibonacci(n): if n == 0: return 0 if n == 1:
- 10Sum of Digits RecursivelyIntermediateCalculate sum of digits recursively.Open example →pydef sum_digits(n): # Base case if n == 0: return 0