CS 240: Data Structures and Algorithms
James Madison University, Spring 2013

HW #2

For this assignment you will use Blackboard to submit a single .py file containing solutions to the following programming exercises. You may use the file hw2.py as a template. Carefully test each function to make sure that it works as expected. These exercises will be graded both on functionality and code quality.

  1. Complete both parts of Exercise 5 from Friday's turtle activity. (10pts)
  2. Complete Exercises 3 and 4 from Monday's List activity. (10pts)
  3. Complete the following Python function so that it conforms to the docstring. There is a helpful section on Python file I/O in section A.6.3 of our textbook. You can test your function on the following two files: simple.txt and picture.txt. Since the second file contains over four hundred polygons, it will take a long time to draw. You can speed up the process using the turtle module's speed function. (5pts)
    
    def drawFaceFile(name):
        """ Draws a collection of faces stored in a file. 
    
            Arguments: name - A string containing a file name.  Each line
            of the indicated file must contain three integers specifying
            the position and size of a face.  The format for one face is:
    
            xpos ypos size
    
            For example, the following two lines:
    
            0 0 50
            60 60 25
            
            would encode two faces: one 50x50 pixel face at position 
            (0, 0), and one 25x25 pixel face at position (60, 60).
            
            No return value. 
        """
        #YOUR CODE HERE.