Not sure how to tackle this [closed]

I have located the book that contains this assignment.

Introduction to Programming Using Python by Y. Daniel Liang

(Okay, due to only having this snippet to go on, I actually found a PDF of the book first, but that had the title of the book, so here we are.)

It does indeed call itself a Python book. In addition to the decidedly unpythonic exercise given in the OP’s question, it even has a whole section (section 15.11) on tail recursion. The very first thing it says in that section, in an emphasized font face:

A tail recursive function is efficient for reducing stack size.

I looked through the rest of the section, and it never mentions the fact that Python does not have tail call optimization. For an explanation of that decision, read Guido’s blog post about it.

This book was published in 2013, so it’s not like it’s outdated or wrestling with an immature platform. My theory is that the author, a “Java Champion” who gives lectures on Java, simply speaks Python with a very heavy Java accent, and the result is barely comprehensible.

My recommendation to the OP is to ask the instructor to use a different textbook – like the official Python tutorials, for example.

Leave a Comment