CS 115 Pre-Lab 8 Instructions

Deadline: Tu 3/10/2015 at 7 AM

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


Part 1: Populating Lists

For this part of the pre-lab, you'll use the online Python 3 tutor to build lists using append.

  1. Enter the following code into the tutor:
    L = []
    for i in range(3):
       L.append(i)
    
    Answer Question 1 in your pre-lab.
  2. Enter the following code into the tutor:
    L = []
    for j in range(5):
       L.append(j ** 2)
    
    Answer Question 2 in your pre-lab.
  3. Enter the following code into the tutor:
    A = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec']
    B = []
    for month in A:
        B.append(month)
    
    Answer Question 3 in your pre-lab. Note that there are more efficient ways to do what this code does -- this is just an example that uses append.

Part 2: Functions

  1. Enter the following code into the tutor:
    import math
    
    
    def PrintHello():
        print("Hello!")  # A
    
    
    def PrintGoodbye():
        print("Goodbye!")  # B
    
    
    def HiFive():
        print("HiFive!")  # C
        return 5
    
    
    def main():
        print("Calling PrintHello")  # D
        PrintHello()
        print("Calling HiFive")  # E
        value1 = HiFive()
        print("Result of HiFive:", value1)  # F
    
    
    main()
    
  2. Answer Question 4 in your pre-lab.

Part 3: 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