Questions
The quiz itself will be similar in difficulty to 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. (But if you’re unsure, before looking up the solution, try figuring it out on your own or testing it out in Visual Studio!)
Data Types
str
literals in Python can be surrounded in either single-quote characters ('like this'
) or double-quote characters ("like this"
), though in COMP110 we prefer the double-quotes. (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?
Expressions
- What is the resulting value and data type of the following expression?
int("20")
- What is the resulting value and data type of the following expression?
str(2023) + str(2023)
- What is the resulting value of the following expression?
type(9 / len( str(110))
- What is the resulting value 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:“Saturday"
. - What data type do expressions with relational operators typically evaluate to?
- What does the following expression evaluate to?
int("10" + "40") > 100 * 2
Conditionals
Every
if
statement must be followed by 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. (If you are unsure, this is a good one to try yourself!) (T/F)All subquestions of this problem will refer to this code snippet:
x: int = int(input("Pick a number: ")) y: int = 10 z: int = 2 x = x - 1 if x < 10: print("A") else: if (x % z) == 0: print ("B") if x == (y + z): print("C") else: print("D")
For the following subquestions, answer with a valid input value for x
that would cause the given letter to print. It is OK for your input to cause other letters to print as well. If there is no such value, write “Unreachable”.
4.1 A
4.2 B
4.3 C
4.4 D
Now, answer with a valid input value for x
that would cause the exact given letter(s) to print (no other letters). If there is no such value, write “Unreachable”.
4.5
A
C
4.6
B
C
4.7
C
4.8
D
Boolean Operators
- What is the result of the following boolean expressions?
5.1.((not False) and True) == True
5.2.(not False) or (True and False)
5.3.True and (7 < 3 * 4 / 6)
5.4.(not False) != True
5.5.not(True and False) and (False or not False)
Memory Diagrams
You can find practice memory diagrams on the Practice Memory Diagrams Page. For this quiz, you should know how to do the ones under “Basics” and “Conditionals”.
More Practice
Check out the weekly tutoring problems for more practice, and be sure to attend tutoring!
Solutions
Data Types Solutions
- T
- F
- F
type()
Expressions Solutions
20
,int
"20232023"
,str
<class 'float'>
(Or justfloat
is sufficient on a quiz.)"44020"
4
4.0
There are two possible answers:
"Saturday"[2] + "Saturday"[1] + "Saturday"[4]
or
"Saturday"[2] + "Saturday"[6] + "Saturday"[4]
bool
True
Conditionals Solutions
F
F
F
4.1 Any value < 11
4.2 Any value >= 11 and odd. (Since
x % z == 0
must be True andz
is 2, this meansx - 1
must be even.)4.3 13
4.4 Any value != 13
4.5 Unreachable
4.6 13
4.7 Unreachable
4.8 Any value >= 11 and even
Boolean Operators Solutions
- 5.1.
True
5.2.True
5.3.False
5.4.False
5.5.True