





































































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!






































































Python PCAP Exam 2026: Certified Associate in Python Programming Practice Test — Data Types, Control Flow, Functions, Exceptions, Object-Oriented Programming & Modules — 190 Multiple-Choice Questions with Answers & Detailed Rationales
Section 1: Python Fundamentals & Syntax (Questions 1-30)
Question 1
What is the correct file extension for Python files?
A. .pyt B. .pt C. .py D. .python
Correct Answer: C
Explanation: Python source files use the .py extension, which is recognized by interpreters and IDEs for proper syntax highlighting and execution.
Question 2
Which of the following is NOT a valid Python variable name?
A. _myVar B. my_var C. 2myVar D. myVar
Correct Answer: C
Explanation: Variable names cannot begin with a digit; they must start with a letter or underscore per Python naming conventions.
Question 3
What will be the output of the following code?
python
x = 5
y = 2
print(x // y)
A. 2. B. 2 C. 3 D. 2.
Correct Answer: B
Explanation: The floor division operator (//) returns the integer quotient, discarding the remainder, so 5 // 2 equals 2.
Question 4
Which operator is used for exponentiation in Python?
A. ^ B. ** C. ^^ D. //
Correct Answer: B
Explanation: The ** operator raises a number to a power; ^ is bitwise XOR and does not perform exponentiation in Python.
Question 5
What is the result of the following expression?
python
print(type(3.14))
A. B. C. D.
C. Comments must end with ; D. Comments cannot span multiple lines
Correct Answer: B
Explanation: Single-line comments begin with # and are ignored by the interpreter; triple- quoted strings can serve as multi-line comments.
Question 9
What will be printed?
python
x = "10"
y = int(x) + 5
print(y)
A. 105 B. 15 C. "105" D. Error
Correct Answer: B
Explanation: int("10") converts string to integer 10, then 10 + 5 = 15, demonstrating explicit type conversion.
Question 10
Which of the following is an immutable data type in Python?
A. list B. dictionary C. set D. tuple
Correct Answer: D
Explanation: Tuples cannot be modified after creation, making them immutable; lists, dictionaries, and sets are mutable.
Question 11
What is the correct way to create an empty set in Python?
A. set() B. {} C. [] D. ()
Correct Answer: A
Explanation: set() creates an empty set; {} creates an empty dictionary, which is a common source of confusion.
Question 12
What will be the output?
python
print(bool(""))
A. True B. False C. Error D. None
Correct Answer: B
Explanation: Empty strings evaluate to False in boolean context; non-empty strings evaluate to True.
Question 13
Which method converts a string to uppercase?
A. upper() B. uppercase() C. toUpper() D. to_upper()
Correct Answer: A
Explanation: The upper() method returns a copy of the string converted to uppercase in Python.
Question 14
Question 17
Which statement about Python indentation is correct?
A. Indentation is optional B. Indentation defines code blocks C. Tabs and spaces cannot be mixed D. Both B and C are correct
Correct Answer: D
Explanation: Python uses indentation to define code blocks, and mixing tabs with spaces causes errors; consistency is required.
Question 18
What will this code output?
python
x = 10
x += 5
print(x)
A. 10 B. 15 C. 5 D. Error
Correct Answer: B
Explanation: The += operator adds the right operand to the variable and assigns the result; 10 + 5 = 15.
Question 19
Which function returns the data type of an object?
A. typeof() B. type() C. datatype() D. gettype()
Correct Answer: B
Explanation: The type() function returns the class type of the object passed as an argument.
Question 20
What is the output of print(3 * "abc")?
A. abcabcabc B. abc C. Error D. 3abc
Correct Answer: A
Explanation: String repetition with * creates multiple copies; 3 * "abc" produces "abcabcabc".
Question 21
Which of the following is a valid Python statement?
A. x = 5; B. x := 5 C. x = 5 D. Both A and C
Correct Answer: D
Explanation: Both x = 5 and x = 5; are valid; semicolons are optional in Python but allowed for multiple statements.
Question 22
What does the input() function return?
A. Integer B. Float C. String D. Boolean
Correct Answer: C
Explanation: input() always returns a string; explicit conversion is needed for numeric operations on user input.
C. Error D. None
Correct Answer: A
Explanation: Small integers are cached in Python, so a and b reference the same object, making identity comparison True.
Question 26
Which escape sequence represents a newline?
A. \t B. \n C. \r D. \b
Correct Answer: B
Explanation: \n inserts a newline character; \t is tab, \r is carriage return, and \b is backspace.
Question 27
What is the correct way to declare a constant in Python?
A. const PI = 3. B. final PI = 3. C. PI = 3. D. constant PI = 3.
Correct Answer: C
Explanation: Python has no true constants; convention uses uppercase names like PI to indicate values that should not change.
Question 28
What will this expression evaluate to?
python
print(5 > 3 and 2 < 4)
A. True B. False C. Error D. None
Correct Answer: A
Explanation: Both conditions are True (5 > 3 and 2 < 4), so the and operator returns True.
Question 29
Which method removes whitespace from both ends of a string?
A. trim() B. strip() C. clean() D. remove()
Correct Answer: B
Explanation: strip() removes leading and trailing whitespace; lstrip() and rstrip() remove from one side only.
Question 30
What is the output of print(round(3.7))?
A. 3 B. 4 C. 3. D. 3.
Correct Answer: B
Explanation: round() rounds to the nearest integer; 3.7 rounds up to 4 using standard rounding rules.
Section 2: Control Flow & Loops (Questions 31-60)
Question 31
What will be the output of this code?
D. Infinite loop
Correct Answer: B
Explanation: The loop increments x until x < 3 is False; when x becomes 3, the loop exits and prints 3.
Question 34
Which keyword is used for conditional execution?
A. when B. if C. case D. switch
Correct Answer: B
Explanation: if statements control conditional execution in Python; there is no switch/case statement in older versions.
Question 35
What does the else clause in a for loop do?
A. Executes if loop breaks B. Executes if loop completes normally C. Executes on error D. Always executes
Correct Answer: B
Explanation: The else clause after a loop executes only if the loop completes without encountering a break statement.
Question 36
What will be printed?
python
for i in range(5):
if i == 3:
break print(i)
A. 0 1 2 3 4 B. 0 1 2 C. 0 1 2 3 D. 3
Correct Answer: B
Explanation: The loop prints 0, 1, 2, then breaks when i equals 3, so 3 and 4 are never printed.
Question 37
Which of the following creates an infinite loop?
A. while True: B. while 1: C. for i in range(0): D. Both A and B
Correct Answer: D
Explanation: Both while True: and while 1: create infinite loops since the condition never becomes False.
Question 38
What is the output?
python
for i in range(2, 8, 2):
print(i, end=" ")
A. 2 4 6 8 B. 2 4 6 C. 2 3 4 5 6 7 D. 4 6 8
Correct Answer: B
Explanation: range(2, 8, 2) generates 2, 4, 6; the stop value 8 is exclusive, so it is not included.
A. Inner loop completes for each outer iteration B. Outer loop completes for each inner iteration C. Nested loops are not allowed D. Both loops run simultaneously
Correct Answer: A
Explanation: In nested loops, the inner loop runs completely for each single iteration of the outer loop.
Question 42
What is the output of this code?
python
x = 5
if x > 3:
print("A")
elif x > 1:
print("B")
else:
print("C")
A. A B. B C. C D. A B
Correct Answer: A
Explanation: The first condition x > 3 is True, so "A" prints; elif and else are skipped once a condition matches.
Question 43
How many times will this loop execute?
python
for i in range(10, 0, -2):
print(i)
A. 5 B. 6 C. 10 D. 4
Correct Answer: A
Explanation: range(10, 0, -2) generates 10, 8, 6, 4, 2; that is 5 iterations before reaching 0 (exclusive).
Question 44
What is the purpose of the continue statement?
A. Exit the loop B. Skip remaining code in current iteration C. Restart the loop from beginning D. Pause execution
Correct Answer: B
Explanation: continue skips the rest of the current iteration and proceeds to the next iteration of the loop.
Question 45
What will be printed?
python
for i in range(3):
for j in range(2): print(i, j)
A. 6 lines of output B. 5 lines of output C. 3 lines of output D. 2 lines of output
Correct Answer: A
Explanation: Outer loop runs 3 times, inner loop runs 2 times for each outer iteration: 3 × 2 = 6 combinations.
C. A range object D. An iterator list
Correct Answer: C
Explanation: In Python 3, range() returns a lazy range object that generates values on demand, saving memory.
Question 49
What will this code output?
python
for i in range(5):
if i % 2 == 0: print(i, end=" ")
A. 0 2 4 B. 1 3 C. 0 1 2 3 4 D. 2 4
Correct Answer: A
Explanation: The condition i % 2 == 0 is True for even numbers; 0, 2, and 4 are printed from range(5).
Question 50
Which loop is best when the number of iterations is unknown?
A. for loop B. while loop C. do-while loop D. foreach loop
Correct Answer: B
Explanation: while loops are ideal when iteration count depends on a condition rather than a predetermined sequence.
Question 51
What is the output?
python
x = 3
y = 5
if x > 2 and y < 10:
print("Yes")
else:
print("No")
A. Yes B. No C. Error D. Nothing
Correct Answer: A
Explanation: Both conditions are True (3 > 2 and 5 < 10), so the and operator evaluates to True and prints "Yes".
Question 52
What happens when break is executed inside nested loops?
A. Exits all loops B. Exits only the innermost loop C. Exits only the outermost loop D. Causes an error
Correct Answer: B
Explanation: break only terminates the loop it is directly inside; outer loops continue their normal execution.
Question 53
What will be printed?
python
i = 1