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
- Go back to the Nested
Structures activity; write a running Python file using Question
22 as the specification.
- 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.
- Switch driver/observer.
- Download the file grid.py
which contains the nested lists of characters that represent the
Connect 4 game board.
- Add a function
draw_grid(with parameterwindow) that draws a row of circles, all the same size, corresponding to each row ingrid.
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 nestedforloops to do this. For example:
- We'll also need a
mainfunction as usual. The function will create a window and calldraw_gridto draw the circles in the window, and anything else that needs doing. Remember to pass your window variable as the first parameter todraw_grid.
. - You can use
griddirectly 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
- Demonstrate your solution and email your final program to me and
your teammate.