Question: Exercise 1 3 - 1 Test the Fibonacci program In this exercise, you'll test the recursive function that prints part of the Fibonacci series. Then,

Exercise 13-1 Test the Fibonacci program
In this exercise, you'll test the recursive function that prints part of the Fibonacci series. Then, you'll test an iterative function that does the same thing, but more efficiently.
Open and test the recursive Fibonacci program
1. In IDLE, open the fibonacci_recursion.py file that's in this folder: python/exercises/ch13
2. Review the code and run it to make sure it works correctly. It should print the first 16 numbers of the Fibonacci series.
3. Modify the code so it calculates a Fibonacci series for 32 numbers, and run it again. Note how slowly it runs.
View the stack for the program
4. Modify the code so it calculates a Fibonacci series for 100 numbers, and run it again. While it's running press Ctrl+C on a Windows system or Command+C on a Mac to interrupt the calculation and view the stack trace. Note that the fib() function has been called numerous times.
5. From the IDLE shell, select Debug \(\rightarrow \) Stack Viewer. In the Stack Viewer, expand a few of the fib() functions and note that they include the values for the local variable named n .
Open and test the iterative Fibonacci program
6. Open the fibonacci_loop.py file that's in the same folder.
7. Review the code and run it to make sure it works correctly.
8. Modify the code so it calculates a Fibonacci series for 100 numbers, and run it. Note how quickly it runs compared to the recursive program.
Exercise 1 3 - 1 Test the Fibonacci program In

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!