Transcript ppt

i>clicker
i-clicker Session 2
Solutions
1
Question 1
Why do we hand trace our code?
A. To verify that our program is bug free.
B. To figure out what our program does.
C. To verify whether our program is solving
the problem.
D. All of the above
E. None of the above
2
Question 2
What is the result of the following
expression type(23.0//3)?
When we answer this
question, we say:
A.
B.
C.
D.
E.
When we enter type(23.0//3) at the shell
command line, Python IDLE Interpreter says:
float (or <class 'float'>)
though // is the floor division, producing a
7.0 Even
result without a fractional part, i.e., 7.0 and not
7.666666666666667, it does return a float
value because one of its 2 operands (here: 23.0)
7
is of float data type.
int
(or <class 'int'>)
None of the above
3
Question 3
The statement
change %= valueOfDime
is equivalent to (can be replaced by)
change = changeCents % valueOfDime
We can assume that all variables have been
created (i.e., they each have been assigned a
value).
A. Yes
B. No
4
Question 4
Execute each statement sequentially, starting
from the top, i.e., the statement at A.
Indicate which expression(s), if any, will
produce an error?
A.
B.
C.
D.
E.
exclamation = 'Ah!'
exclamation * 3
exclamation *= 3
exclamation += 'Ah!'
None of the above
5
Question 5
What is the output of the following Python
code fragment:
exclamation = 'Ah!Ah!Ah!Ah!'
print(exclamation[9:])
A.
B.
C.
D.
E.
Ah!
Ah!Ah!
Ah!Ah!Ah!
An error
None of the above
6