Lab 6
Use PythonTutor to study recursive calls
Submit after the end of the lab session
Overview
For this lab, you will use the PythonTutor to observe recursive calls as they are represented in computer memory.
Instructions, questions, and code writing
- Download the zip folder for the lab.
- The zip folder has three files, each with a recursive function defined:
factorial, recurrence1 and recurrence2. For each file, do the following steps:
- Paste the code into the PythonTutor.
- Below the function definitions in the PythonTutor editor, add a function call with an argument that only requires the simple, base case. For example, for the factorial function, add these two lines of code:
result = factorial(0) print(result)
Since factorial returns a value, it makes sense to assign it to a variable and then print it out. However, unscramble1 doesn't return a value --- you can just call the function with an empty string. Note that unscramble2 does return a value. - Next, try a function call that causes the recursion to go one extra level.
- Finally, try function calls that go multiple levels. You don't need to step through the whole process, but run through enough steps so that you see some function calls starting to return, either with a print (recurrence1) or with return values (factorial and recurrence2).
- Write a summary of your experiences running the PythonTutor on the three files. Devote about one paragraph for each file. It sould include the function calls you tried, how the arguments change with each recursive call, whether each call prints or returns a value, and a summary statement of what you observed.
- A statement that summarizes your completion of the lab. As appropriate, the statement should
include the following:
- Who you worked with on the lab
- Any difficulties you encountered
- Your summary of your experience
- + .5 --- Your submission is clearly formatted.
- + .5 --- Your submission includes a summary statement and includes how you collaborated.
- + .5 / 1.0 --- You submitted most of the lab (0.5) or you submitted all of the lab (1.0).
- + .5 --- Your lab submission is generally correct.
Deliverable
Create a text or pdf file that contains the following:
Put your file in a folder, zip it and submit it under Lab 6 on D2L. Check that your submitted zip file is complete.
Grading
Your lab submission will be graded using the following rubric: