Sample Midterm #2
These are sample questions that are very similar to the ones I
will ask on the midterm. The actual midterm will be about this length.
- Evaluate each expression. If any cannot be evaluated, say why.
- "hello"+ "goodbye"
- 7 * True
- 6 / "spam"
- True and (not False or True)
- 'she' in "hehisandits"
- Convert the following into Python.
- “hello” follows “goodbye” in the character
ordering of the computer
- The value of the variable answer is true or the value of the
variable y is less than 126
- The function gleep is called with an argument of −21
- Convert the following into a “for” loop.
i = 1
while i < 10:
print i * "x"
i += 3
- What does the following function do when given a string as the first argument
and a string containing only one character as the second argument?
def x(s, c):
i = 0
while i < len(s):
if s[i] == c:
i += 1
- What does the following function do?
if len(s) < 2:
return s[ -1] + a(s [1: -1]) + s
- What does the following program do?
d = dict ()
line = input ("EOF to stop > ")
for i in line:
d[i] = d.get(i, 0) + 1
u = d.keys()
for i in u:
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012