Questions
The quiz itself will be similar in difficulty but longer in length than these practice questions.
Solutions for each problem can be found at the bottom of this page.
Memory Diagrams
- Produce a memory diagram for the following code snippet, being sure to include its stack and output.
Boolean Operators
- What is the result of the following boolean expressions?
3.1.((not False) and True) == True
3.2.(not False) or (True and False)
3.3.True and (7 < 3 * 4 / 6)
3.4.(not False) != True
3.5.not(True and False) and (False or not False)
Conditionals
- Every
if
statement must have a pairedelse
branch. (T/F) - Lines contained in an
else
branch in Python do not have to be indented. (T/F) - You can name a variable
else
in your program without Python confusing your variable’s name and theelse
keyword. (T/F) - Given the following code snippet, what is the printed output with the specified values for
x
andy
?
7.1. When x = 3, y = 5?
7.2. When x = 5, y = 3?
7.3. When x = -5, y = 1?
7.4. When x = 13, y = 8?
7.5. When x = 4, y = 3?
While Loops
Given the following code snippet, what is the printed output once it completes?
Given the following code snippet, what is the printed output once it completes?
Lists
10.1. The values in a list cannot be changed while your program is running. (T/F)
10.2. The last index of a list is the length of the list. (T/F)
10.3. You can initialize an empty list with no items. (T/F)
10.4. For the purposes of this class, all items in a list are of the same type. (T/F)
10.5. While loops inside a function may continue looping after a return statement is reached. (T/F)
10.6. The condition of a while loop must be a boolean expression (T/F)
List Memory Diagrams
Produce a memory diagram for the following code snippet, being sure to include its stack and output.
Produce a memory diagram for the following code snippet, being sure to include its stack and output.
List Code Tracing
- Given the following code snippet, answer the questions below.
13.1. What is the value oflist_1
once the code snippet completes?
13.2. What is the value ofi
on line 13 during the last call tochange_and_check
?
13.3. How many total frames are created on the stack throughout the run of this program (including the globals frame)?
Solutions
Memory Diagrams
Boolean Operators
- 3.1.
True
3.2.True
3.3.False
3.4.False
3.5.True
Conditionals
- False
- False
- False
- 7.1. 16.0
7.2. 2.0
7.3. -3.0
7.4. 3.0
7.5. 1
While Loops
- 3
3
“1303132” - “036910875421”
Lists
10.1. False
10.2. False
10.3. True
10.4. True
10.5. False
10.6. True
List Memory Diagrams
List Code Tracing
- 13.1.
[6, 7, 5, 3, 0]
13.2. 4
13.3. 4