< Back

Lecture 7 - Test Review


As usual, create a directory to hold today's activities:

$ mkdir ~/cs170/labs/lab7 
$ cd ~/cs170/labs/lab7 

Lab Activity 1
Test Review

In addition to the written portion of the test, there will be a coding portion. This will be done on the computers. For practice, attempt the following exercises, alone:

  1. Write a simple tkinter program that draws a filled in rectangle with a length of 400 and a height of 300 to the center of the window, and writes your name inside that rectangle.

  2. Create a class called Point_3D, which represents a point in 3 dimensional space. This class should have methods for adding points together (which is just the sum of each component). This method should return a new Point_3D, instead of modifying one of the points. You should also include a method that can be used when printing the point.

  3. Create a class called Bin, which stores a list of all of the elements currently inside of the bin. Include a method store_item(item) that allows you to add objects to the bin. Create another class called RecycleBin, which inherits the Bin class. Your RecycleBin class should have at least a method called empty(), which removes everything from the bin.

  4. In a file called read_lists.py, create a program that will read in a 2-dimensional list from a text file. The file read in should be structured as n lines of n characters each. Your program should read this file into a 2-dimensional structure, and print this list out to the user.

    After reading the file, the user should then be allowed to enter two integers, and your program should print the character stored in that location of the 2-dimensional list. If the location entered by the user does not exist, print an error message.

    sample_file.txt:
    abcd
    efgh
    ijkl
    mnop
    
    $ python3 read_lists.py
    The current structure of the list is:
    a b c d
    e f g h
    i j k l
    m n o p
    
    Which row? 1
    Which column? 3
    h
    $ python3 read_lists.py
    The current structure of the list is:
    a b c d
    e f g h
    i j k l
    m n o p
    
    Which row? 4
    Which column? 4
    Those indicies to not exist in the current list!
    $
    

Submission

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

cd ~/cs170/labs
tar czvf lab7.tgz lab7/

To submit your activity, go to inquire.roanoke.edu. You should see an available assignment called Lab Assignment 7. Make sure you include a header listing the authors of the file. If you worked in a pair, each member should submit their own copy of the lab assignment.

In-Class Notes