CSSE 120 -- Intro. to Software Development

Homework 4 (a bit longer than previous assignments)

  1. Complete the assigned reading for the next session, Zelle sections 4.4-4.7.
  2. (31 pts) Complete the ANGEL quiz over this reading. You'll find this on the course ANGEL page, under Lessons → Homework → Homework 4 → String Manipulation
  3. Bonus (10 pts), due at start of Session 5. You'll have to do this before Session 6 anyway; doing it before Session 5 will earn you you the bonus pointsIn session 6, we will begin using a new integrated development environment (IDE) called PyDev that runs inside Eclipse. Freshman laptops that have not been reloaded have some of these steps done, as noted below.
    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.

     

  4. (10 pts) Complete Programming Exercise 3.2 on page 72 of Zelle. Again include appropriate comments. Name your program area.py. Your program should:

    1. Prompt the user to enter the diameter and price of the pizza.
    2. Use the math module to get the value of pi. (If you don't remember how to import the math module, see the transcript from Session 1.)
    3. Display the cost per square inch, with a descriptive label.
  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.py , Polygon.py , and Star.py.

    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 (Pizza.py, Polygon.py, Star.py) to the corresponding drop box in the Homework 4 folder on ANGEL. (The Star Dropbox is in the HW 5 folder).

  8. Bonus (10 pts). Can you figure out how to replace the vertices-building code that we gave you with a list comprehension instead of a loop with an accumulator (as we did it)? [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 .

    If you do the list comprehension bonus simply state that you have done the list comprehension bonus after your name within the file.  No need to submit a separate file.  Just submit one Pizza.py file for example total.
  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.