webartifex / intro-to-python

An intro to Python & programming for wanna-be data scientists
https://code.webartifex.biz/alexander/intro-to-python
MIT License
882 stars 87 forks source link

fibonacci(0) corner case #27

Open webartifex opened 3 years ago

webartifex commented 3 years ago

Check corner cases for iterative fibonacci() function in Chapter 4

webartifex commented 3 years ago

Simply exit early if i == 0

webartifex commented 3 years ago

Note that runtime of fib(20) is 39 steps in cached recursive version vs 19 in the iterative version!

webartifex commented 3 years ago

Use inspect module to indent debug output for fibonacci() (cf., Programming Interview Problems, p. 8)