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 50 minutes to complete the exam.
A hint for allocating your time:
makeLogoPoints(), that is called from the drawLogo() function shown in Figure 3. Your answer should pass the test cases given.
You only need to finish the function definition for makeLogoPoints()—don't worry about adding any more test cases, or any of the import pygame or pygame.init() type stuff that might be needed. Don't worry about the while(True): loop or the pygame.display.update(), or any of that stuff—assume that has already been done correctly. Just focus on this one function definition.
If you like, you can cross out the two lines after the function header, and write the function a different way—as long as it will work (i.e. it will pass the tests, and work with drawLogo() correctly.)
def makeLogoPoints(x,y,width): points = [] points.append( (x,y) ) # point 1 from diagram
# Fill in the rest of this function...
check_expect("makeLogoPoints(50,100,50)", makeLogoPoints(50,100,50), [(50,100),(100,100),(100,50),(50,50),(50,100),(75,50),(100,100)]) check_expect("makeLogoPoints(150,250,100)", makeLogoPoints(150,250,100), [(150,250),(250,250),(250,150),(150,150),(150,250),(200,150),(250,250)])
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)
drawLogo() from the handout (Figure 3). 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()| Expression | Equivalent Expression without not operator |
Value of a=4 and b=3 |
|---|---|---|
|
a > 5 and b > 6 |
False |
|
||
|
||
|
||
|
||
not (a == 5) and not (b == 5) |
>>> 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: ?