From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

A recursive factorial function

A recursive factorial function - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

A recursive factorial function

- [Instructor] Now that you know how to implement the factorial function using iteration, we're going to see how to do the same thing recursively. You need to open up the file factorial recursive in your exercise files. And if you're using git, git checkout. And I'm going to put this b flagged there which you don't need because you're not creating this but I'm creating this as I go. So that's going to be git checkout -b and it's going to be 02_04b for beginning. Like I say this b here is when you're creating the branch and checking it out in one command. Whereas you just need to check out the branch which is already being created. So I know on my new branch. And I'm ready to go so let's close it up. So, recursive factorial. First of all we need a base case so if n is less than or equal to a one. Let's make a note that this is in fact the base case using a comment. So if it's the base case is then, we want to return…

Contents