This week we had our first midterm. I found it quite simple, but after receiving the test I realized I made stupid little mistakes from maybe rushing. That has aways been my problem with programming so I realize I need to work on that in the future.
Recursion
In class, we've began to explore deeper into the use and function of recursion in python. Recursion is basically the idea of repeating a function while using itself in the process. My dad, being a computer scientist, would teach me recursion and always explained recursion by explaining how if you placed 2 mirrors in front of each other it would create an infinite tunnel of reflections because both mirrors would be reflecting their image, and then their image reflecting their image, and so on. In programming however, recursion is used by defining a function that calls upon itself to return a value or perform a function.
For recursion to work, there must always be a base case or cases. Without a base case, a recursive function would fall into an infinite loop that would never return a value or perform an action because it would never know when to stop. The rest of the function is a set of rules and recursive sub calls which are called the general case.
No comments:
Post a Comment