Name: ________________________________________________________
Umail Address: __________________________________@ umail.ucsb.edu
Please write your name only on this page. That allows me to grade your exams without knowing whose exam I am grading.
This exam is closed book, closed notes, closed mouth, cell phone off,
except for:
There are 100 points worth of questions on the exam, and you have 85 minutes to complete the exam.
A hint for allocating your time—on your first pass through the exam:
If you do that, you'll complete your first pass thorugh the exam in 50 minutes, and still have 35 minutes to
# drawBisPolygon (turtle, float, int) => void
# consumes:
# t: a turtle (that was already constructed) we'll use to draw the polygon
# r: the radius of the polygon
# n: the number of sides the polygon has
# produces: nothing
# side-effect:
# if n is not an even number, nothing is drawn.
# Otherwise:
# the turtle draws a polygon of n sides, centered at 0,0, exactly
# as in drawPolygon.
# Then, lines are drawn bisecting the polygon between every pair of points
# that are exactly opposite one another.
def drawBisPolygon(t,r,n):
# @@@ Put a line of code here that returns immediately without
# drawing anything if the number of points is not an even
# number.
# @@@ Put in code to draw the polygon.
# Hint: you can draw it with one line of code---you don't need
# the whole for loop thing.
# @@@ Now write code to connect the dots for all the bisecting lines
# Hint: the code will be similar to the code from drawStar
check_expect("numRoots(1,2,3)",numRoots(1,2,3),0)
check_expect("numRoots(1,2,-3)",numRoots(1,2,-3),2)
check_expect("numRoots(1,4,4)",numRoots(1,4,4),1)
ithPointOnUnitCircleX() from the handout.numRoots() that you wrote as the answer to question 2.check_expect() is one we've been using throughout the course—the usual definition is given below.
def check_expect(test,check,expect):
if (check == expect):
print "Test " + test + " passed."
else:
print "Test " + test + " failed: expected " + str(expect) + \
" but I got " + str(check)
check_expect()check_expect()check_expect()>>> bus = "MTD"
>>> lines = [15,23,24,27]
>>> times = (0,15,30,45)
>>> bus[0]
______
>>> bus[-1]
______
>>> bus[1:]
______
>>> lines[0]
______
>>> lines[1:2]
______
>>> type(lines[1:2])
______
>>> type(lines[1])
______
>>> type(times)
______
>>> len(times[1:])
______
>>> times[1:3]
______
>>>
End of Exam
Total points: ?