CSSE 120 -- Intro. to Software Development

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

  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. Bonus (10 pts). Due at start of session 5 if you want the bonus. 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, with PyDev, C, and Subclipse plugins installed already. (Upperclassmen need to do all the steps; freshmen can skip to step 3.) Instructions.
    2. 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.
  4. Everything below this is due at least 48 hours after assigned.
  5. (14 pts total for parts 4 and 5) 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 "4a.", range(6)
    2. [2, 3, 4, 5, 6, 7]
      Answer: print "4b.", 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]
  6. 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 "5a.", myList[0]
    2. [3, 6, 8]
      Answer: print "5b.", 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.

  7. 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.

  8. Bonus #2 (10 pts)  Animate the figures in #6 so that they rotate around the center of the circle.
  9. 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 #6 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 .
  10. 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.