Concepts on Quiz 0
Quiz 0 will cover the following concepts:
- Syllabus and course policies - be familiar with them!
- Lessons 0 through 7
- Challenge Questions 0 through 2 including Environment Diagrams
Questions
The quiz itself will be similar in difficulty but longer in length than these practice questions. In addition to these questions, you should review all of your lesson responses on Gradescope. The kinds of questions you responded to on Gradescope will also be on the quiz.
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.
- Produce a memory diagram for the following code snippet, being sure to include its stack and output.
Data Types
str
literals in Python can be surrounded in either single-quote characters or double-quote characters, though in COMP110 we prefer the latter. (T/F)TRUE
andFALSE
are valid bool values in Python. (T/F)- An
int
literal can begin with a zero, but cannot end with a zero. (T/F) - What function can we use to identify the type classification of any object in Python?
- What is the resulting data type of the following expression?
int("20")
Expressions
- What is the evaluation of the following expression?
type(9 / len( str(110))
- What is the result of the following expression?
"440" + "20"
- What value of x would cause the following expression to evaluate to
True
?(3 + x) == (55 % 2 ** 4)
- What value does the following expression result in, and what is its type?
2 + 2 / 2 ** (2 * 0)
- Using subscription syntax and concatenation, write an expression that evaluates to
"tar"
using the following string:“the brown, lazy dog!"
. - What data type do expressions with relational operators evaluate to?
- What does the following expression evaluate to?
int("10" + "40") > 100 * 2
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
?
18.1. When x = 3, y = 5?
18.2. When x = 5, y = 3?
18.3. When x = -5, y = 1?
18.4. When x = 13, y = 8?
18.5. When x = 4, y = 3? - Every then or else block of an
if-then
statement is reachable by some value, regardless of the test conditions specified by theif
statement.
Solutions
Memory Diagrams
Data Types
- T
- F
- F
type()
- int
Expressions
<class 'float'>
- “44020”
- 4
- 4.0
- “the brown, lazy dog!”[0] + “the brown, lazy dog!”[12] + “the brown, lazy dog!”[5]
- bool
- True
Conditionals
- False
- False
- False
- 18.1. 16.0
18.2. 2.0
18.3. -3.0
18.4. 3.0
18.5. 1 - False