CSSE 120 -- Intro. to Software Development

Homework 4

A great place and time to do these exercises are the CSSE lab F-217 during student assistant hours, since you can get immediate help from the lab assistant.

  1. Complete the assigned reading for the next session, Zelle, § 4.1 - 4.5.
  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. (10 pts) Complete Programming Exercise 3.2 on page 72 of Zelle. 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.
    3. Display the cost per square inch, with a descriptive label.

    Upload your area.py file to the Area dropbox in the Homework 4 folder.

  4. (14 points) 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] 

  5. (14 more points) 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 (i.e., the last element of myList )
    5. [0, 2]
    6. The position of 4 in myList.
    7. The length of myList.

    Upload the file containing your answers to this problem and the previous one to the RangeAndList dropbox in the Homework 4 folder. on ANGEL.

  6. (45 points - 15 for each shape) Some Geometry with Lists. For this problem you will draw 3 shapes (also see pictures below):

    Start with this geometry.py file. Note that it:

    Your job is to make the 3 shapes appear, per the TODO's in the geometry.py file. You MUST use the vertices list in a meaningful way to get credit. 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:

    Upload your geometry.py file to the Geometry Graphics Program dropbox in the Homework 4 folder.

  7. Bonus (10 points). In the previous problem, we gave you some vertices-building code:
    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))
    
    Your job for this bonus problem is to replace the above code with a single-line list comprehension statement, that builds the list of vertices.
  8. Bonus (10 points). Animate one or more of your figures from the pizza/polygon/star problem above.
  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.