CS 115 Pre-Lab 9 Instructions

Deadline: Tu 3/24/2015 at 7 AM

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


Part 1: Creating and accessing 2D lists

At this point, you should be very comfortable using and manipulating one-dimensional lists. Lists usually are created and accessed through loops. For example, this code creates a list of 10 elements, where each element has a value of 0:

my_list = []    # create an empty list
for i in range(10):
    my_list.append(0)  

We can also create and initialize a list in a single statement:

list_of_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

The elements of a list can be of any data type, including lists. For example:

two_three = [ [1, 2, 3], [10, 11, 13] ] 

Here, we have a list with two elements. Each of the elements is itself a list, which makes two_three a two-dimensional list.

Each of the elements of two_three is a row, and each row has three elements (columns).

Practice: building 2D lists with append

Copy and paste the following code into the online Python 3 tutor, run it one step at a time, and answer Question 4 in your pre-lab.

v = 0
two_d = []            # create an empty list
for i in range(5):
    two_d.append([])  # append an empty list to two_d
    for j in range(4):
        two_d[i].append(v)   # two_d[i] is the empty list that we just created.
                             # here, we are adding elements to it.
        v += 1 

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