
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































This paper contains 500 original multiple-choice questions organized into ten chapters covering Python Basics: Output, Variables, Types and Input; Operators, Expressions and the math Module; Strings, Indexing, Slicing and Formatting; Decisions: if, elif, else and Boolean Logic; Loops: for, while, range, break and continue; Lists and Tuples; Dictionaries and Sets; Functions, Parameters, Return Values and Scope; Files, Exceptions and Modules; Objective Assessment Tasks: Code Tracing and Problem Solving.
Each question has one best answer. Work through a chapter without looking at the key, then check your answers in the Answer Key and Rationales section at the end. Every answer comes with a short rationale explaining why it is correct, so you can review the concept behind any question you miss.
Suggested approach: aim for 80% or better on each chapter before moving on, and revisit the rationales for every missed question. Mixing chapters in a timed session of 50 questions in 60 minutes is good preparation for cumulative exams.
Ch. Topic Questions
1 Python Basics: Output, Variables, Types and Input^ 1–
2 Operators, Expressions and the math Module^ 51–
3 Strings, Indexing, Slicing and Formatting^ 101–
4 Decisions: if, elif, else and Boolean Logic^ 151–
5 Loops: for, while, range, break and continue^ 201–
6 Lists and Tuples^ 251–
7 Dictionaries and Sets^ 301–
8 Functions, Parameters, Return Values and Scope^ 351–
9 Files, Exceptions and Modules^ 401–
10 Objective Assessment Tasks: Code Tracing and Problem Solving^ 451– Answer Key and Rationales —
6. What is the type of the value "42"? A. float B. str C. bool D. int Verified Answer: B. str Rationale: Quotes make it a string. 7. What does type(True) return? A. B. C. D. **Verified Answer: B. ** Rationale: Boolean type. 8. What does int("25") + 5 evaluate to? A. "255" B. 255 C. An error D. 30 Verified Answer: D. 30 Rationale: Converts string to integer. 9. What does "25" + "5" evaluate to? A. 30 B. "255" C. An error D. 255 Verified Answer: B. "255" Rationale: String concatenation. 10. What happens when evaluating "25" + 5? A. 255 B. A TypeError is raised C. 30 D. "255" Verified Answer: B. A TypeError is raised Rationale: Cannot concatenate str and int. 11. What does float("3.5") return? A. 3 B. 3. C. "3.5" D. An error Verified Answer: B. 3. Rationale: Conversion to float.
12. What does int(7.9) return? A. An error B. 7. C. 8 D. 7 Verified Answer: D. 7 Rationale: int() truncates toward zero. 13. Predict the result Python gives for int(-7.9): A. - B. 7 C. - D. -7. Verified Answer: C. - Rationale: Truncation toward zero. 14. What does round(2.675, 2) return in standard CPython? A. 3 B. 2. C. 2. D. 2. Verified Answer: C. 2. Rationale: Binary floating-point representation of 2.675 is slightly below. 15. What does round(7.5) return? A. 7 B. 7. C. 8. D. 8 Verified Answer: D. 8 Rationale: Ties round to the nearest even integer; 8 is even. 16. What does round(6.5) return? A. 6 B. 7. C. 6. D. 7 Verified Answer: A. 6 Rationale: Banker's rounding to even. 17. The input() function always returns a value of type: A. float B. int C. str D. It depends on what the user types Verified Answer: C. str Rationale: Convert explicitly.
24. After x = 5 and x = x + 2, the value of x is: A. 52 B. 2 C. 5 D. 7 Verified Answer: D. 7 Rationale: Reassignment. 25. After a = 3 and b = a and a = 10, the value of b is: A. 3 B. 13 C. 10 D. None Verified Answer: A. 3 Rationale: b refers to the earlier integer object. 26. What does a, b = 1, 2 do? A. Creates a tuple named a B. Assigns (1, 2) to both C. Raises an error D. Assigns 1 to a and 2 to b Verified Answer: D. Assigns 1 to a and 2 to b Rationale: Tuple unpacking. 27. After a, b = 1, 2 and a, b = b, a, the values are: A. a = 2, b = 1 B. a = 1, b = 2 C. a = 2, b = 2 D. a = 1, b = 1 Verified Answer: A. a = 2, b = 1 Rationale: Swap idiom. 28. A comment in Python begins with: A. // B. # C. /* D. -- Verified Answer: B. # Rationale: Single-line comment. 29. Python uses indentation to: A. Make code pretty only B. Declare variables C. Mark comments D. Define code blocks Verified Answer: D. Define code blocks Rationale: Required syntax.
30. Python variable names are: A. Limited to one letter B. Case-insensitive C. Case-sensitive, so Total and total are different D. Always uppercase Verified Answer: C. Case-sensitive, so Total and total are different Rationale: Case matters. 31. What does len("Python") return? A. 6 B. "Python" C. 5 D. 7 Verified Answer: A. 6 Rationale: Number of characters. 32. Which statement creates a constant by convention in Python? A. final max = 100 B. #define MAX 100 C. const max_size = 100 D. MAX_SIZE = 100 Verified Answer: D. MAX_SIZE = 100 Rationale: Uppercase naming convention. 33. What does print(type(10 / 2)) display? A. B. C. D. **Verified Answer: B. ** Rationale: True division returns float. 34. What does print(10 / 2) display? A. 2 B. 5. C. 5 D. 5. Verified Answer: D. 5. Rationale: Float result. 35. Which keyword is used to import a module? A. import B. require C. include D. using Verified Answer: A. import Rationale: E.g. import math.
42. What does abs(-4.5) return? A. 5 B. -4. C. 4. D. 4 Verified Answer: C. 4. Rationale: Absolute value. 43. What does max(3, 9, 2) return? A. 2 B. 3 C. 9 D. 14 Verified Answer: C. 9 Rationale: Largest argument. 44. What does min("b", "a", "c") return? A. "c" B. An error C. "a" D. "b" Verified Answer: C. "a" Rationale: Lexicographic order. 45. A syntax error occurs when: A. A file is missing at run time B. Code violates Python's grammar rules, such as a missing colon C. A value is the wrong type at run time D. Division by zero occurs Verified Answer: B. Code violates Python's grammar rules, such as a missing colon Rationale: Detected before execution. 46. A runtime error (exception) occurs when: A. The file is saved B. Comments are used C. A problem arises while the program is running, such as dividing by zero D. The code has a missing colon Verified Answer: C. A problem arises while the program is running, such as dividing by zero Rationale: E.g. ZeroDivisionError. 47. A logic error is: A. A runtime crash B. A mistake that produces wrong results without crashing C. A missing import only D. A syntax mistake Verified Answer: B. A mistake that produces wrong results without crashing Rationale: Requires testing.
48. What does print(int("0x1A", 16)) display? A. An error B. 26 C. 1A D. 16 Verified Answer: B. 26 Rationale: Base-16 conversion accepts the 0x prefix. 49. What does print(bin(5)) display? A. 0b B. 101 C. 0x D. 5 Verified Answer: A. 0b Rationale: Binary representation string. 50. What does print(9 ** 0.5) display? A. 81 B. 4. C. 3. D. 3 Verified Answer: C. 3. Rationale: Square root via exponent.
56. When the interpreter runs 10 - 4 - 3, the result is: A. 9 B. 3 C. - D. 11 Verified Answer: B. 3 Rationale: Left-to-right. 57. What does 2 + 3 * 4 evaluate to? A. 14 B. 20 C. 24 D. 9 Verified Answer: A. 14 Rationale: Multiplication first. 58. Consider the code (2 + 3) * 4. What results? A. 20 B. 14 C. 9 D. 24 Verified Answer: A. 20 Rationale: Parentheses first. 59. What does 8 / 2 * 4 evaluate to? A. 1. B. 16. C. 16 D. 4. Verified Answer: B. 16. Rationale: Left-to-right; float result. 60. What does 7 / 0 raise? A. NameError B. TypeError C. ValueError D. ZeroDivisionError Verified Answer: D. ZeroDivisionError Rationale: Division by zero. 61. What does 5 == 5.0 evaluate to? A. False B. None C. An error D. True Verified Answer: D. True Rationale: Numeric equality.
62. Predict the result Python gives for 3 != 4: A. True B. 1 C. False D. None Verified Answer: A. True Rationale: Not equal. 63. What does not True evaluate to? A. False B. None C. True D. 0 Verified Answer: A. False Rationale: Logical negation. 64. What does True and False evaluate to? A. None B. 1 C. False D. True Verified Answer: C. False Rationale: Both must be true. 65. What does True or False evaluate to? A. True B. None C. False D. 0 Verified Answer: A. True Rationale: Either true. 66. What does 0 or "default" evaluate to? A. True B. 0 C. False D. "default" Verified Answer: D. "default" Rationale: or returns the first truthy operand. 67. What does 5 and 0 evaluate to? A. False B. 5 C. 0 D. True Verified Answer: C. 0 Rationale: and returns the first falsy operand.
**74. After x = 2 and x = 4, x equals: A. 8 B. 16 C. 6 D. 24 Verified Answer: B. 16 Rationale: Power assignment. 75. What does 7 % 2 == 1 test? A. Whether 7 is even B. Whether 7 is divisible by 7 C. Whether 7 is odd D. Whether 7 is prime Verified Answer: C. Whether 7 is odd Rationale: Odd check. 76. The expression n % 2 == 0 is True when n is: A. Even B. Negative only C. Odd D. Prime Verified Answer: A. Even Rationale: Even check. 77. What does math.sqrt(16) return after import math? A. 256 B. 4. C. 16 D. 4 Verified Answer: B. 4. Rationale: Returns float. 78. What does math.floor(3.7) return? A. 3 B. 3. C. 3. D. 4 Verified Answer: A. 3 Rationale: Largest integer ≤ x. 79. What does math.ceil(3.2) return? A. 3 B. 4 C. 3. D. 4. Verified Answer: B. 4 Rationale: Smallest integer ≥ x.
80. What does math.pi represent? A. The constant π ≈ 3. B. Euler's number C. A function D. The value 3 exactly Verified Answer: A. The constant π ≈ 3. Rationale: Constant. 81. What does math.pow(2, 3) return? A. 8 B. 9 C. 6 D. 8. Verified Answer: D. 8. Rationale: Returns float. 82. What does pow(2, 3) (built-in) return? A. 6 B. 8 C. 9 D. 8. Verified Answer: B. 8 Rationale: Integer for integer arguments. 83. What does math.fabs(-3) return? A. - B. -3. C. 3 D. 3. Verified Answer: D. 3. Rationale: Float absolute value. 84. What does divmod(17, 5) return? A. 3. B. (2, 3) C. (3, 2) D. [3, 2] Verified Answer: C. (3, 2) Rationale: Quotient and remainder tuple. 85. Which operator checks identity rather than equality? A. == B. is C. = D. in Verified Answer: B. is Rationale: Same object.
92. What does 15 % 4 + 15 // 4 evaluate to? A. 6 B. 3 C. 4 D. 7 Verified Answer: A. 6 Rationale: 3 + 3. 93. The value of (7 > 3) + (2 > 5) is: A. 0 B. 1 C. True D. 2 Verified Answer: B. 1 Rationale: True is 1, False is 0. 94. What does abs(-3) ** 2 evaluate to? A. - B. 3 C. 9 D. 6 Verified Answer: C. 9 Rationale: abs first, then square. 95. When the interpreter runs -3 ** 2, the result is: A. 6 B. - C. 9 D. - Verified Answer: B. - Rationale: Unary minus applies after exponentiation. 96. To compute the average of a, b and c correctly, use: A. a + b + c / 3 B. a + b + c // 3 C. (a + b + c) % 3 D. (a + b + c) / 3 Verified Answer: D. (a + b + c) / 3 Rationale: Parentheses required. 97. What does round(3.14159, 2) return? A. 3. B. 3. C. 3 D. 3. Verified Answer: A. 3. Rationale: Two decimal places.
98. The math.isclose() function is useful for: A. Checking string equality B. Rounding integers C. Comparing floats within a tolerance D. Closing files Verified Answer: C. Comparing floats within a tolerance Rationale: Avoids float equality problems. 99. What does 0b1010 evaluate to? A. 5 B. 2 C. 10 D. 0b1010 as a string Verified Answer: C. 10 Rationale: Binary literal. 100. Consider the code 25 ** 0.5 == 5. What results? A. False B. An error C. 5. D. True Verified Answer: D. True Rationale: 5.0 == 5 is True.