This week we focused on recursion. A function is recursive if it calls itself. Recursion is an essential tool for computer scientists because it is necessary for some problems and is provides a solution that is concise and elegant compared to iterative solutions which may be long, complex and inelegant. We also practiced tracing recursive code. To better understand recursion and how it works, it's useful to trace the function with examples of a call with the smallest possible input, with the next largest possible input and then continuing to problems of any larger size for more confidence.
Also this week, on the 29th of January, our first assignment was due. I worked on it with Tal and Adam. We had some issues figuring out how to use __repr__ and __str__ in our function. I asked in my tutorial and I received a good answer that's cleared up my understanding. __repr__ are similar in many ways which make it quite confusing. They both return strings but __repr__ returns what you chose to return as the representation and __str__ returns a string that normally gives a kind of "english" summary of what's going on.
No comments:
Post a Comment