COMPSCI 61A Study Guide - Midterm Guide: Cheat Sheet, Pure Function, New York State Route 57
CS 61A Structure and Interpretation of Computer Programs
Spring 2018 Midterm 1
INSTRUCTIONS
• You have 2 hours to complete the exam.
• The exam is closed book, closed notes, closed computer, closed calculator, except one hand-written 8.5" ×11"
crib sheet of your own creation and the official CS 61A midterm 1 study guide.
• Mark your answers on the exam itself. We will not grade answers written on scratch paper.
Last name
First name
Student ID number
CalCentral email ([email protected])
TA
Name of the person to your left
Name of the person to your right
All the work on this exam is my own.
(please sign)
POLICIES & CLARIFICATIONS
• If you need to use the restroom, bring your phone and exam to the front of the room.
• You may use built-in Python functions that do not require import, such as min,max,pow, and abs. You may
not use functions defined on your study guide unless clearly specified in the question.
• For fill-in-the blank coding problems, we will only grade work written in the provided blanks. You may only
write one Python statement per blank line, and it must be indented to the level that the blank is indented.
• Unless otherwise specified, you are allowed to reference functions defined in previous parts of the same question.
2
1. (12 points) Frame of Thrones
For each of the expressions in the table below, write the output displayed by the interactive Python interpreter
when the expression is evaluated. The output may have multiple lines. If an error occurs, write “Error”, but
include all output displayed before the error. To display a function value, write “Function”. The first two rows
have been provided as examples.
The interactive interpreter displays the value of a successfully evaluated expression, unless it is None.
Assume that you have first started python3 and executed the statements on the left.
from operator import add, sub
def winterfell(a, b):
a
b
return b(a+1, b(a))
da, ny = 20, 18
while da > ny:
da = ny
da, ny = ny + 1, da + 3
def tar(gar, yen):
if print(yen):
print(yen + 1)
return gar(yen)
def st(ar, k=None):
return lambda a, y: ar(y, a)
night = st(sub)
king = st(st(pow))
def jon(sn, ow):
print(ow)
jon = sn(ow)
print(ow)
return jon
def snow(ow):
def tarly(snow):
return ow + snow
ow += 2
return tarly
Expression Interactive Output
sub(pow(10, 2), 1) 99
print(4, 5) + 1 4 5
Error
(print(2) or 3) // (0 or 1)
winterfell(2, print)
ny
tar(lambda x: x-7, 8)
night(king(2, 3), 4)
jon(snow(5), 2)
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
We will not grade answers written on scratch paper. All the work on this exam is my own. (please sign) You may not use functions de ned on your study guide unless clearly speci ed in the question: for ll-in-the blank coding problems, we will only grade work written in the provided blanks. For each of the expressions in the table below, write the output displayed by the interactive python interpreter when the expression is evaluated. If an error occurs, write error , but include all output displayed before the error. The rst two rows have been provided as examples. The interactive interpreter displays the value of a successfully evaluated expression, unless it is none. Expression sub(pow(10, 2), 1) print(4, 5) + 1. Error (print(2) or 3) // (0 or 1) winterfell(2, print) ny tar(lambda x: x-7, 8) night(king(2, 3), 4) jon(snow(5), 2)