CS 115 Pre-Lab 14 Instructions

Deadline: Tu 5/5/2015 at 7 AM

Refer to the Week 16 reading or other resources as necessary to complete this assignment.


Recursion

Before you start writing your own code, you'll use the the online Python 3 tutor to trace the execution of recursive functions. Try to predict what will happen before stepping through the code in the tutor.

  1. Enter the following code into the tutor:
    def f(x):
        if x <= 1: return 1
        temp = f(x - 1)
        return x * temp
    
    
    def main():
        a = f(4) # Statement 1
    
    
    main()
    
  2. Trace through the execution of Statement 1, and answer Question 1 in the pre-lab.
  3. Enter the following code into the tutor:
    def reverse(s):
        if len(s) <= 1: return s
        return s[-1] + reverse(s[0:-1])
    
    
    def main():
        a = reverse('H') # Statement 1
        b = reverse('seawolf') # Statement 2
    
    
    main()
    
  4. Trace through the execution of Statement 2, and answer Question 2 in the pre-lab.

Submit the pre-lab (due Tu at 7 AM)

Review your answers, and then click the Next button at the bottom of the Moodle quiz. Once you do that, you should see something similar to this:
Quiz attempt summary

Click the Submit all and finish button. You MUST do this so that your pre-lab can be graded! Once you have submitted your quiz, you should see something similar to this at the top of your Moodle window. The important part is that the State shows up as Finished.
Quiz confirmation