From the course: Python: Recursion
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: The fundamentals of recursion - Python Tutorial
From the course: Python: Recursion
Solution: The fundamentals of recursion
(soft music) - [Instructor] Okay so solution time, not much needs to be changed but the main thing is here that we have this base case here. So on line 12, I've got if the line length is greater than the maximum length, then we can stop and the way we stop is simply by returning without doing anything further. And then the way that we guarantee movement towards that base case is if you look at our recursive function call on 16, you can see that I'm passing in the turtle that was given to you anyway but then the parameter or the argument that I'm using is whatever the current line length is plus the increment I've defined up here on line eight. Thus you can play around with these numbers, you can have a different maximum length of different increments. But the important thing is that the three laws of recursion need to be met. Again so we have the base case, that's lines 12 and 13. We have movement towards the…
Contents
-
-
-
-
(Locked)
Exceptions to GitHub Codespaces1m 30s
-
(Locked)
The ingredients of a recursive algorithm4m 11s
-
Recursion in action3m 26s
-
(Locked)
The factorial function: Iterative version3m 26s
-
(Locked)
A recursive factorial function4m 13s
-
(Locked)
Winding and unwinding the call stack in recursion6m 46s
-
(Locked)
Challenge: Fix the recursive algorithm1m 11s
-
(Locked)
Solution: The fundamentals of recursion1m 8s
-
(Locked)
-
-
-
-
-
-
-
-