From the course: Python: Recursion

Unlock the full course today

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

Solution: The fundamentals of recursion

Solution: The fundamentals of recursion - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

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