Learn Without Walls
← Back to Module 2

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?

  • my_var
  • 2nd_place
  • _private
  • totalCount
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)
  • 5
  • 13
  • 16
  • 11
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?

  • 3.4
  • 2
  • 3
  • 5
Correct: b) The modulo operator % returns the remainder of division. 17 / 5 = 3 remainder 2.

Question 4

What does type(10 / 2) return?

  • <class 'int'>
  • <class 'str'>
  • <class 'bool'>
  • <class 'float'>
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"))?

  • 6
  • 7
  • 5
  • 8
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?

  • 8
  • 7.0
  • 7
  • 8.0
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"?

  • print("She said "hi"")
  • print('She said "hi"')
  • print("She said 'hi'")
  • 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")?

  • True
  • False
  • 0
  • Error
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)?

  • 20
  • 24
  • 9
  • 14
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)?

  • It prints Age: 25
  • It prints Age:
  • It raises a TypeError
  • It prints 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?

  • camelCase (myVariable)
  • snake_case (my_variable)
  • PascalCase (MyVariable)
  • UPPER_CASE (MY_VARIABLE)
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"))
  • 3
  • 3.14
  • "3"
  • Error
Correct: a) float("3.14") converts the string to 3.14, then int(3.14) truncates to 3.

Quiz Results