CSSE 120 -- Intro. to Software Development

Homework 4 (a bit longer than usual if you do the bonus)

Note:  The solutions to some of the problems are due at the start of next class.  The other problems have a 24 hour extension.  Problems with an extension are noted below.

  1. Complete the assigned reading for the next session, Zelle sections 4.4-4.7.
  2. (24 pts) Complete the Angel quiz over this reading. You'll find this on the course Angel page, under Lessons → Homework → Homework 4 → String Manipulation and File Processing
  3. (14 pts for parts 3 and 4) Using range. Write a Python range expression for each of the following lists. You should write your expressions in a new file, rangeAndList.py, in IDLE, using print statements to print the answers. Answers to the first two are given as examples.
    1. [0, 1, 2, 3, 4, 5]
      Answer: print "3a.", range(6)
    2. [2, 3, 4, 5, 6, 7]
      Answer: print "3b.", range(2, 8)
    3. [-2, -1, 0, 1, 2]
    4. [1, 3, 5, 7, 9]
    5. [1, 4]
    6. [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
    7. [2, 1, 0, -1, -2]
  4. Manipulating Lists. Continuing with the rangeAndList.py file you created for the previous problem, add the following line of code:

    myList = [3, 6, 8, 11, 7, 4, 5, 9, 10, 0, 2]

    Now add statements to your program that print each of the following numbers or lists using expressions involving myList. Again, a couple of examples are given.

    1. 3
      Answer: print "4a.", myList[0]
    2. [3, 6, 8]
      Answer: print "4b.", myList[:3]
    3. [8, 11, 7, 4]
    4. 2
    5. [0, 2]
    6. The position of 4 in myList.
    7. The length of myList.

    Upload the file containing your answers to problems 3 and 4 to the RangeAndList dropbox in the Homework 4 folder on ANGEL.

  5. Some Geometry with Lists. For this problem you'll write three small, separate but similar, graphics programs: Pizza, Polygon, and Star.

    Each program prompts the user to enter an odd integer, number. Then the programs draw pictures as follows:

    The pictures below show what the display of your programs should look like for a couple of cases.

    Examples when number is 5:

    Examples when number is 7:

    Copy and paste liberally during this assignment, but get Pizza right before moving on to Polygon and Star.

    You may wish to use the following code, which generates an appropriate list of Points for any value of number:

        # Some constants
        radius = 150
        centerX = 200
        centerY = 200
        
        # Builds vertices list
        vertices = []
        for i in range(number):
            x = radius * cos(2 * pi * i / number) + centerX
            y = radius * sin(2 * pi * i / number) + centerY
            vertices.append(Point(x, y))
    

    Do you see how you can iterate over the Points stored in the list vertices in order to find endpoints for the lines?

    When you have finished and tested your programs, submit each Python source file to the corresponding drop box in the Homework 4 folder on ANGEL.

  6. Bonus (10 pts). In session 6, we will begin using a new development environment called PyDev that runs inside Eclipse. Freshman laptops have some of these steps done, as noted below. You'll have to do this for session 6 anyway; doing it early gets you the bonus points:
    1. Install Eclipse by following these instructions. (Upperclassmen need to update to Eclipse 3.4; freshmen can skip this.)
    2. Install and configure PyDev for Eclipse by following these instructions. (Upperclassmen need to do all of this; freshmen can skip the beginning and start at step 3 of Install the PyDev plug-in for Eclipse.)
    3.  Install and configure Subclipse for Eclipse by following these instructions. (Everyone needs to do this.)
    4. To get your bonus points, during session 5 you will do the following:
      1. Launch Eclipse and show us your Hello World Python program running.
      2. In Eclipse, show us your modified "spam.py" file that you checked out using Subclipse. If you didn't get this working, instead choose Window > Open Perspective > Other..., and show us that "SVN Repository Exploring" appears in the list.
  7. [Has a 24 hour extension] Bonus #2 (10 pts)  Animate the figures in #5 so that they rotate around the center of the circle.
  8. [Has a 24 hour extension] Bonus #3 (10 pts). Can you figure out how to replace the vertices-building code that we gave you with a list comprehension instead? [If you submit solutions for #5 that use list comprehensions, you will receive bonus points]  Note that the term "list comprehension is not mentioned in the Zelle textbook, but you can find it in today's PowerPoint slides on-line.  Further examples are available in the Python tutorial at http://docs.python.org/tut/node7.html#SECTION007140000000000000000 .
  9. The Python Package Index, a repository of extensions to Python, is often called the Cheese Shop. Watch this bizarre video to see where the reference comes from.

If you need help, recall that in addition to your instructor, the student assistant lab hours are a resource for you. The times are listed in the Course Syllabus.