A-level Python · Lesson 1 of 9Recursion and call stacks
OCR H446 algorithms / AQA 7517 recursion
Write a recursive factorial function with a base case.
← All A-level Python lessons
Understanding recursive calls
Recursion solves a problem by calling the same function on a smaller input. Every recursive solution needs a base case that stops further calls. Trace each call and the values returned as the call stack unwinds.
Watch out: A missing or unreachable base case leads to repeated calls until Python raises a recursion error.
A free TutorSyntax programming lesson. About our teaching approach.