CS8—Midterm 1
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:

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


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


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



  2. (5 pts) What values will be printed by this code?
    for i in range(4):
                 print (i)           
    



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

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



  4. (5 pts) What values will be printed by this code?
    for i in range(7,4,-1):
      print (i)
    



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



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



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



    3. (5 pts) What is the value of the expression?




  6. (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.

    L drawn by a Turtle
    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.






  7. Answer the following questions about the value of expressions



    1. (5 pts) What is the value of the expression

      56 % 2



    2. (5 pts) What is the value of the expression

      59 % 5



    3. (5 pts) What is the value of the expression

      7 // 5



    4. (5 pts) What is the value of the expression

      7 / 5



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

      7 % 5






End of Exam

Total points: ?