Wed Apr 1
You have up to 20 minutes. You may use a standard calculator if necessary, but no text book, notes, or computer. You may not type the program in to the Python IDLE environment. You should be able to evaluate what the program does on your own. When we say “what is the output,” you should write just the result of the print
statements, and label that as output. If you need to write other computations as scratch work, label that as scratch.
What is the output of the following Python program?
z1 = 10
z2 = 3
print(z2)
z2 = z2 + z1
if z2 > 5:
print("wow")
print(z1)
Output:
3
wow
10
What is the output of the following Python program?
xy = 5
zq = 3
print(xy*2)
if xy > 7:
print("yes")
print(xy + zq)
print("xy")
Output:
10
8
xy
Evaluate the following prefix expression. What result does it produce?
(* (+ 3 5) (- 6 2))
⇒ (* 8 (- 6 2))
⇒ (* 8 4)
⇒ 32
Evaluate the following postfix expression. What result does it produce?
4 1 2 + * 3 -
put initial numbers on stack
STACK: 4 1 2
add 1 + 2
STACK: 4 3
multiply 4 * 3
STACK: 12
put next number on stack
STACK: 12 3
subtract 12 - 3
STACK: 9