Changelog
Dec 2: Memory diagram 2 subquestions had some small errors/typos for what lines had docstrings and expressions. Before, line 1 was erroneously not included as having a docstring and line 8 was erroneously counted as including an expression.
Quiz 00 Practice Problems
The following questions will help solidify concepts learned in class, as well as prepare you for the quizzes and final!
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 and challenge questions on Gradescope.
If you find yourself feeling lost, please ask for help in office hours or tutoring.
Multiple Choice and True/False
What is a
booldata type in Python?Data type for storing text
Data type for storing whole numbers such as
-10,3, or100Data type for storing True/False values
Data type for storing any type of information
Data type for storing numbers with a decimal point such as
1.0,3.14, or-0.1
SHOW SOLUTION
The correct answer is C.
What is an
intdata type in Python?Data type for storing text
Data type for storing whole numbers such as
-10,3, or100Data type for storing True/False values
Data type for storing any type of information
Data type for storing numbers with a decimal point such as
1.0,3.14, or-0.1
SHOW SOLUTION
The correct answer is B.
What is a
strdata type in Python?Data type for storing text
Data type for storing whole numbers such as
-10,3, or100Data type for storing True/False values
Data type for storing any type of information
Data type for storing numbers with a decimal point such as
1.0,3.14, or-0.1
SHOW SOLUTION
The correct answer is A.
An
intliteral can begin with any number of zeroes.True
False
SHOW SOLUTION
The correct answer is B.
Which of the following literals are a
float?4"4"4.0"4.0"
SHOW SOLUTION
The correct answer is C.
What function can you use to determine the type of an object in Python?
print()str()len()type()
SHOW SOLUTION
The correct answer is D.
What is the type of the following expression?
1.5 + 2intfloatstrboolTypeError
SHOW SOLUTION
The correct answer is B.
What is the type of the following expression?
len("cottage")intfloatstrboolTypeError
SHOW SOLUTION
The correct answer is A.
What is the result of the following expression?
"110" + "110"220"110110"TypeError"220""110""110"
SHOW SOLUTION
The correct answer is B.
What is the result of the following expression?
102 // 52020.4""20"TypeError21
SHOW SOLUTION
The correct answer is A.
What is the type of this value in Python?
"True"boolstrTypeErrorintfloat
SHOW SOLUTION
The correct answer is B.
What value will the following expression evaluate to?
"map"[1]m"m"a"a"TypeError
SHOW SOLUTION
The correct answer is D.
What will the following expression evaluate to?
int(3.8 + 1)4.853.814TypeError
SHOW SOLUTION
The correct answer is D.
Expressions
What are the types of the following expressions and what values do they evaluate to? If a
TypeErroroccurs, just writeTypeError.1.1.
1.5 + 21.2.
"hehe" * 21.3.
len("110") ** 21.4.
str(110) * 2.11.5.
float("100.0") / 201.6.
21 // 2 ** 2 + 31.7.
float("220") >= float("100" + "100")1.8.
int("COMP 110"[5]) + 99.01.9.
(42 % 4) == (79 % 11)1.10.
int(4.99)
SHOW SOLUTION
The correct answers are:
1.1. Type: float Value: 3.5
1.2. Type: str Value: "hehehehe"
1.3. Type: int Value: 9
1.4. TypeError
1.5. Type: float Value: 5.0
1.6. Type: int Value: 8
1.7. Type: bool Value: False
1.8. Type: float Value: 100.0
1.9. Type: bool Value: True
1.10. Type: int Value: 4
Which of the following expressions correctly concatenates two strings together?
"clam" * "chowder""clam" + "chowder""clam" , "chowder""clam" : "chowder"
SHOW SOLUTION
The correct answer is B.
When using subscription syntax, what index does Python start with?
-101""True
SHOW SOLUTION
The correct answer is B.
- What value would you substitute for
xto make the following expression True?
(3 + x) == ((55 // 11) ** 2)SHOW SOLUTION
The correct answer is 22.
- Use subscription notation, string concatenation, and the string
"nevermind"to write an expression that evaluates to"nvm".
SHOW SOLUTION
The correct answer is "nevermind"[0] + "nevermind"[2] + "nevermind"[5].
Functions
- What is a function call, and how does it differ from a function definition?
SHOW SOLUTION
A function definition is where you create the function and specify what it does. It includes the function signature and everything indented below it. The signature consists of the function name, parameters, the types of the parameters, and the return type. The function body contains the code block that executes when the function is called. A function call occurs when you invoke or execute the function by writing the function name followed by parentheses. If the function accepts inputs, the parentheses will contain the values assigned to the parameters, also known as arguments. When a function definition is encountered, the function body is not executed; it is bypassed until the function is called. To call a function, you must first define it.
- What is the difference between parameters and arguments in the context of functions?
SHOW SOLUTION
Parameters are the variables listed in the function signature that define the expected inputs. Your parameters will hold the values passed into the function when the function is called. These values that are assigned to the parameters are called arguments. Arguments are the actual values passed to the function when it is called.
- When you call a function, once the function is executed, where do you return back to?
SHOW SOLUTION
After the function is executed, you will return back to the point in the code where the function was called.
- If you never encounter a return statement in your function, what is your return value?
SHOW SOLUTION
If there is no return statement in a function, it returns None by default.
What does the
len()function do in Python?Converts a value to a string
Rounds a number to the nearest whole number
Returns the length of a sequence, such as a
strConverts a string to a number
Counts the digits in an int
SHOW SOLUTION
The correct answer is C.
Given the following function definition, answer the following questions.
def evaluate_length(name: str) -> int: """This function returns the length of the name.""" return len(name)6.1. What is the result of the following function call?
evaluate_length("airplane")6.2. What is the type of the parameter
name? What is the return type of this function?
SHOW SOLUTION
The correct answers are:
6.1. 8
6.2. The type of name is str and the return type of the function is int.
Given the following function definition, answer the following questions.
def tablespoons_to_teaspoons(tablespoons: int) -> str: """This functions tells you how many teaspoons are in the given number of tablespoons.""" return str(tablespoons * 3) + " teaspoons"7.1. Write a function call to
tablespoons_to_teaspoonsthat returns the string"9 teaspoons".7.2. What is the type of the parameter
tablespoons? What is the return type of this function?
SHOW SOLUTION
The correct answers are:
7.1. tablespoons_to_teaspoons(tablespoons=3)
7.2. The type of tablespoons is int and the return type of the function is str.
Function Signatures
- What is a function signature, and why is it significant?
SHOW SOLUTION
A function signature refers to the first line of a function definition, where the def keyword is used. Following the def keyword is the function name, and after the function name is a set of parentheses that enclose the parameter list. After the parameter list comes the return type. The function signature is important because it defines how the function can be called and what kinds of inputs and outputs are expected. Without a signature, you wouldn’t know what parameters to provide or even how to call the function, since the function name would be missing.
- Write the function signature for a function called
pos_or_negthat takes as input an integer and returns"Positive"if the integer is positive and returns"Negative"if the integer is negative. Usenumberas the name of the parameter.
SHOW SOLUTION
The correct answer is:
def pos_or_neg(number: int) -> str:
- Write the function signature for a function called
gcdthat takes two integers as input and returns the integer that is their greatest common divisor. Usenum_oneandnum_twoas your parameter names.
SHOW SOLUTION
The correct answer is:
def gcd(num_one: int, num_two: int) -> int:
Memory Diagrams
Trace a memory diagram of the following code listing and answer the following subquestions.
1 def total_price(calzones: int, strombolis: int) -> int: 2 """Returns the total price for the order of food, including a service fee of $3.""" 3 return calzones_price(calzones=calzones) + strombolis_price(strombolis=strombolis) + 3 4 5 def calzones_price(calzones: int) -> int: 6 """Returns the price of the given number of calzones.""" 7 return 7 * calzones 8 9 def strombolis_price(strombolis: int) -> int: 10 """Returns the price of the given number of strombolis.""" 11 return 8 * strombolis 12 13 print(total_price(calzones=4, strombolis=2))1.1. What line(s) do function definition signatures appear on?
1.2. What line(s) do docstrings appear on?
1.3. What line(s) do expressions appear on?
1.4. What line(s) do function calls appear on?
1.5. Write a function call to
calzones_pricethat would evaluate to28.
SHOW SOLUTION

The correct answers are:
1.1. Lines 1, 5, and 9
1.2. Lines 2, 6, and 10
1.3. Lines 3, 7, 11, 13
1.4. Lines 3 and 13
1.5. calzones_price(calzones=4)
Trace a memory diagram of the following code listing and answer the following subquestions.
1 """Functions of a circle...""" 2 3 4 def main() -> None: 5 """Entrypoint of Program""" 6 print(circumference(radius=1.0)) 7 print(area(radius=1.0)) 8 return None 9 10 11 def area(radius: float) -> float: 12 """Calculate area of a circle""" 13 return 3.14 * radius ** 2 14 15 16 def circumference(radius: float) -> float: 17 """Calculate circumference""" 18 return 2 * 3.14 * radius 19 20 21 main()2.1. What line(s) do function definition signatures appear on?
2.2. What line(s) do docstrings appear on?
2.3. What line(s) do expressions appear on?
2.4. What line(s) do function calls appear on?
2.5. What is the return type of
area? What is the return type ofmain?
SHOW SOLUTION

The correct answers are:
2.1. Lines 1, 4, 11, and 16
2.2. Lines 5, 12, and 17
2.3. Lines 6, 7, 13, 18, 21
2.4. Lines 6, 7, and 21
2.5. area has a return type of float and main has a return type of None.
Solutions
Multiple Choice and True/False
- C
- B
- A
- B
- C
- D
- B
- A
- B
- A
- B
- D
- D
Expressions
1.1. Type: float Value: 3.5
1.2. Type: str Value: "hehehehe"
1.3. Type: int Value: 9
1.4. TypeError
1.5. Type: float Value: 5.0
1.6. Type: int Value: 8
1.7. Type: bool Value: False
1.8. Type: float Value: 100.0
1.9. Type: bool Value: True
1.10. Type: int Value: 4
B
B
22"nevermind"[0] + "nevermind"[2] + "nevermind"[5]
Functions
A function definition is where you create the function and specify what it does. It includes the function signature and everything indented below it. The signature consists of the function name, parameters, the types of the parameters, and the return type. The function body contains the code block that executes when the function is called. A function call occurs when you invoke or execute the function by writing the function name followed by parentheses. If the function accepts inputs, the parentheses will contain the values assigned to the parameters, also known as arguments. When a function definition is encountered, the function body is not executed; it is bypassed until the function is called. To call a function, you must first define it.
Parameters are the variables listed in the function signature that define the expected inputs. Your parameters will hold the values passed into the function when the function is called. These values that are assigned to the parameters are called arguments. Arguments are the actual values passed to the function when it is called.
After the function is executed, you will return back to the point in the code where the function was called.
If there is no return statement in a function, it returns None by default.
C
6.1. 8
6.2. The type of name is str and the return type of the function is int.
7.1. tablespoons_to_teaspoons(tablespoons=3)
7.2. The type of tablespoons is int and the return type of the function is str.
Function Signatures
A function signature refers to the first line of a function definition, where the def keyword is used. Following the def keyword is the function name, and after the function name is a set of parentheses that enclose the parameter list. After the parameter list comes the return type. The function signature is important because it defines how the function can be called and what kinds of inputs and outputs are expected. Without a signature, you wouldn’t know what parameters to provide or even how to call the function, since the function name would be missing.
def pos_or_neg(number: int) -> str:def gcd(num_one: int, num_two: int) -> int:Memory Diagrams

1.1. Lines 1, 5, and 9
1.2. Lines 2, 6, and 10
1.3. Lines 3, 7, 11, 13
1.4. Lines 3 and 13
1.5. `calzones_price(calzones=4)`

2.1. Lines 4, 11, and 16
2.2. Lines 5, 12, and 17
2.3. Lines 6, 7, 8, 13, 18, 21
2.4. Lines 21, 6, and 7
2.5. `area` has a return type of `float` and `main` has a return type of `None`.