Module 2 Quiz: Variables & Data Types
12 questions • Select the best answer for each question
Question 1
Which of the following is NOT a valid Python variable name?
Correct: b) Variable names cannot start with a number.
2nd_place starts with 2, so Python will raise a SyntaxError.Question 2
What is the output of the following code?
x = 5
x = x + 3
x = x * 2
print(x)
x = x + 3
x = x * 2
print(x)
Correct: c) x starts as 5, then x = 5 + 3 = 8, then x = 8 * 2 = 16.
Question 3
What is the result of 17 % 5?
Correct: b) The modulo operator
% returns the remainder of division. 17 / 5 = 3 remainder 2.Question 4
What does type(10 / 2) return?
Correct: d) In Python 3, the
/ operator always returns a float, even when dividing evenly. 10 / 2 produces 5.0.Question 5
What is the output of print(len("Hello\n"))?
Correct: a)
\n is a single escape character (newline). H-e-l-l-o-\n = 6 characters total.Question 6
What does int(7.9) return?
Correct: c)
int() truncates (cuts off) the decimal part. It does not round. 7.9 becomes 7.Question 7
Which of the following is the correct way to print She said "hi"?
Correct: b) Using single quotes for the outer string allows double quotes inside without escaping. Option c would print single quotes instead of double quotes.
Question 8
What is bool("0")?
Correct: a)
"0" is a non-empty string (it contains the character "0"), so it is truthy. Only an empty string "" is falsy.Question 9
What is the output of print(2 + 3 * 4)?
Correct: d) Multiplication has higher precedence than addition (PEMDAS). So 3 * 4 = 12 first, then 2 + 12 = 14.
Question 10
What happens when you run print("Age: " + 25)?
Correct: c) You cannot concatenate a string and an integer with
+. You need to convert the integer to a string first: "Age: " + str(25).Question 11
Which naming convention is recommended for Python variables?
Correct: b) Python convention (PEP 8) recommends snake_case for variable names: lowercase letters with underscores between words. UPPER_CASE is used for constants.
Question 12
What is the value of result after this code runs?
result = int(float("3.14"))
Correct: a)
float("3.14") converts the string to 3.14, then int(3.14) truncates to 3.