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.
(10 pts) Complete Programming Exercise 3.2 on page 72 of Zelle. Include appropriate comments. Name your program area.py. Your program should:
Upload your area.py file to the Area dropbox in the Homework 4 folder.
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.
[0, 1, 2, 3, 4, 5] print "4a.", range(6) [2, 3, 4, 5, 6, 7] print "4b.", range(2, 8) [-2, -1, 0, 1, 2] [1, 3, 5, 7, 9] [1, 4] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] [2, 1, 0, -1, -2] (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.
3 print "5a.", myList[0] [3, 6, 8] print "5b.", myList[:3] [8, 11, 7, 4] 2 (i.e., the last element of myList ) [0, 2] 4 in myList. 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.
(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.
Upload your geometry.py file to the Geometry Graphics Program dropbox in the Homework 4 folder.
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.