E01, 10M, Phill Conrad, UC Santa Barbara

08/10/2010

**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:

- You are permitted
**one sheet of paper**(max size 8.5x11") on which to write notes - These sheets will be collected with the exam, and might not be returned
- Please write your name on your notes sheet

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 a question is worth 10 points, spend no more than 5 minutes on it
- if a question is worth 20 points, spend no more than 10 minutes on it
- if a question is worth 40 points, spend no more than 20 minutes on it
- etc.

If you do that, you'll complete your first pass thorugh the exam in 50 minutes, and still have 35 minutes to

- revisit any questions where you need more time
- check your work.

- (5 pts) I promised you this question, so here it is:

Which of these is a backslash? Circle one: / \

- (5 pts) What values will be printed by this code?

for i in range(4): print (i)

- (5 pts) What values will be printed by this code?

for i in range(4,8,2): print (i)

- (5 pts) What values will be printed by this code?

for i in range(7,4,-1): print (i)

- Answer the following questions about the expression 2 + 3 * 5

- (5 pts) What is the left operand of the * operator?

- (5 pts) What is the right operand of the + operator?

- (5 pts) What is the value of the expression?

- (5 pts) What is the left operand of the * operator?
- (40 pts) Here is the definition of a Python function that draws the letter L, using the cTurtle module. At the moment, the width and height of the L are
*hard coded*: width is 50 and height is 100.

def drawL(t): t.left(90) t.forward(100) t.backward(100) t.right(90) t.forward(50) t.backward(50)

Rewrite the function, generalizing it so that it can make a letter L of any height or width.

Note that the function starts with the Turtle at the lower left hand corner of the L, facing right, and ends with the Turtle at the same spot. Your function should also do that, even after you generalize it.

**Important Note:**Focus**only**on rewriting the`drawL`

function. Don't worry about things like`import cTurtle`

, or`fred=cTurtle.Turtle("turtle")`

or any of that other stuff, which is**not**relevant to the problem I'm asking you solve here. You won't get any extra points for including that stuff—in fact, points*may be deducted*.

I*only*want the re-written`drawL`

function.

- Answer the following questions about the value of expressions

- (5 pts) What is the value of the expression

56 % 2

- (5 pts) What is the value of the expression

59 % 5

- (5 pts) What is the value of the expression

7 // 5

- (5 pts) What is the value of the expression

7 / 5

- (5 pts) What is the value of the expression

7 % 5

- (5 pts) What is the value of the expression

Total points: ?