CPSC 120 B




Lecture
MWF 10:50am - 11:50am
Lab
MWF 12:00pm - 1:00pm

Scotty Smith

Office
Trexler 365-B
Office Hours
Monday / Thursday
3:00pm - 5:00pm
Email
chssmithATroanoke.edu

< Back
Printable Copy

Lecture 38 - Test Review


Unusual day today. You only need to create a directory called lab38 under labs. You can store all files you work on today in this directory.


Review

As usual, you should work on the written handout of this review before working on the coding portion.

Create a file called test_review.py in your lab38 directory. You should write your answers to the following questions in that file.

  1. Write a function that takes a two-dimensional list of ints and returns True if all of the columns sum to the same value and False otherwise. For example:

    >>> magic_cols([[4, 9, 2], [3, 5 ,7], [8, 1, 6]])
    True
    >>> magic_cols([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    False
  2. Write a function that takes a list of ints and returns a new list that contains all of the ints in the input list, but no duplicates. For example:

    >>> remove_dups([1, 2, 3, 4, 5])
    [1, 2, 3, 4, 5]
    >>> remove_dups([1, 2, 3, 2, 1])
    [1, 2, 3]
  3. Write a Python function that returns a dictionary that represents a Vigenère Square. This dictionary can be used to assist in encoding a Vigenère cipher. You should generate this dictionary dynamically, as opposed to hard-coding the values.

    >>> square = generate_vigenere()
    >>> for key in square:
    ...     print(key, "->", square[key])
    
    a -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    c -> ['c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b']
    b -> ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a']
    e -> ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd']
    d -> ['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c']
      .
      .
      .

Lab Assignment 38

 

Challenge

Game of life is back. And I'm going to try my hardest to get you to write the graphical version of the game. So this is back! You will likely need to copy your game_of_life.py file into your lab38 directory.

$ cd /cs120/labs/lab38
$ cp ../lab37/game_of_life.py .
$ ls
game_of_life.py

As you have no doubt seen, watching the game of life through the terminal window is incredibly difficult. The 1's and 0's flying past the screen do very little to aid in your visual of what is going on. Let's layer a Graphical Interface on top of your 2-d list representation, which hopefully will make it easier to visualize.

Details

In the same file as above, create a new function called draw_game. This function should take the game board as a parameter, plus any additional information necessary to perform the drawing. You should be able to simply call draw_game in the same place you have been calling print_game, with minimal changes else where.

Your visual should consist of a 2-d grid, where each cell in the grid represents one of the values from the 2-d list of values representing the game board. Cells that are valued 0 will not be filled in, while cells that are valued 1 will be filled in with a color of your choosing (traditionally black).

Your grid should fill as much of the window as possible. As such, you should decide the size of the cells based off the dimensions of the window, as opposed to specifying a default grid size.

Example


Submission

When you have finished, create a tar file of your lab38 directory. To create a tar file, execute the following commands:

cd ~/cs120/labs
tar czvf lab38.tgz lab38/

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Lab Assignment 38. Only one of your pair should submit your activity. Make sure both partners are listed in the header of your files.

Do not forget to email your partner today's files!


Last modified: Thu Nov 7 21:44:28 EST 2013