Concepts on Quiz 2
Before working through these practice questions, you should first carefully read this page on Quiz Expectations.
Quiz 2 will cover the following concepts:
- Lessons 13 through 17
Questions
The quiz itself will be similar in difficulty but longer in length than this practice worksheet.
Solutions for each problem can be found at the bottom of this page.
Conceptual Questions
- The values in a list cannot be changed while your program is running. (T/F)
- The last index of a list is the length of the list. (T/F)
- You can initialize an empty list with no items. (T/F)
- For the purposes of this class, all items in a list are of the same type. (T/F)
- While loops inside a function may continue looping after a return statement is reached. (T/F)
- The condition of a while loop must be a boolean expression (T/F)
- Global variables are limited to the scope of the function they are declared in. (T/F)
- Variables can have the same name but store different values as long as they are defined in the same scope. (T/F)
- Named constants should be used to store values that may change throughout the program. (T/F)
- When using a for in loop, on the first line of the loop you must specify the type of the variable (variable refers to
i
infor i in nums
). (T/F)
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.
Code Tracing
Given the following code snippet, answer the questions below.
13.1. What is the printed output once the code snippet completes?
13.2. What are the values of the global variablesa
,b
, andc
once the code snippet completes?Given the following code snippet, answer the questions below.
14.1. What is the value oflist_1
once the code snippet completes?
14.2. What is the final value ofi
in line 13?
14.3. How many total frames are created on the stack throughout the run of this program (including the globals frame)?
Function Writing
Write a function called
odd_and_even
. Given a list ofints
,odd_and_even
should return a new list containing the elements that are odd and have an even index.
Example Usage:
Write a function named
vowels_and_threes
. Given a string,vowels_and_threes
should return a new string containing the characters that are either at an index that is a multiple of 3 or a vowel (one or the other, not both). You can assume that the input string is all lowercase, for simplicity.
Example Usage:
Solutions
Conceptual Questions
- False
- False
- True
- True
- False
- True
- False
- False
- False
- False
Memory Diagrams
Code Tracing
13.1.
[3, 7, 10, 13]
13.2. a = 3, b = 0, c = 13.514.1.
[6, 7, 5, 3, 0]
14.2. 3
14.3. 4
Function Writing
Note: Your solution does not need to be identical to these, these are just two of many possible solutions.