CSci 157 - Lab 11

The purpose of this lab is to gain experience with accessing/modifying data stored in nested lists.

Warmup. Review Model 1 of Nested Structures together. If we append a list to grid must it have seven elements? Does it even have to be a list?

Part 1

  1. Go back to the Nested Structures activity; write a running Python file using Question 22 as the specification.
     
  2. Write a second Python file for Questions 23/24. Demonstrate these to the instructor.

Part 2

In this section you'll write a program to display the Connect 4 grid data in a window.

  1. Switch driver/observer.
     
  2. Download the file grid.py which contains the nested lists of characters that represent the Connect 4 game board.
     
  3. Add a function draw_grid (with parameter window) that draws a row of circles, all the same size, corresponding to each row in grid.
    If the value in grid is ' ', the corresponding circle is white (or transparent). Otherwise, the circle is red for 'R' and yellow for 'Y'. Use nested for loops to do this. For example:

     
  4. We'll also need a main function as usual. The function will create a window and call draw_grid to draw the circles in the window, and anything else that needs doing. Remember to pass your window variable as the first parameter to draw_grid.
    .  
  5. You can use grid directly in your functions. What property of this variable allows you to do this? Think in terms of variable scope.

    Add a comment to the right of any statement that introduces a new variable (including grid and any function parameters) that label the type of scope those variables have. You choices (from last Friday's lecture) are:
    • global scope
    • local scope
    • block scope
     
  6. Demonstrate your solution and email your final program to me and your teammate.