Python Institute PCAP sample questions with explanations, traps, topic labels, and IT Mastery route links.
These original sample questions are designed to help you check how the exam topics appear in decision-style prompts. They are not taken from the live exam.
Use these sample questions as a guided self-assessment for Certified Associate Python Programmer (PCAP) topics such as data structures, slicing, functions, exceptions, object-oriented programming, modules, files, and exact execution order. The prompts emphasize tracing code and explaining why a close distractor fails.
The sample set below is part of the Python Institute PCAP guide path:
Work through each prompt before opening the explanation. PCAP questions often turn on one precise rule: mutation versus rebinding, exception flow, attribute lookup, or the scope of an operation.
Topic: Slice assignment and mutation
What is printed by this code?
1nums = [1, 2, 3, 4]
2part = nums[1:3]
3part.append(99)
4nums[1:3] = part
5print(nums)
[1, 2, 3, 4, 99][1, 2, 3, 99, 4][1, 2, 3, 4]TypeError because slices cannot be assigned lists.Best answer: B
Explanation: nums[1:3] creates a new list containing [2, 3]. Appending 99 changes part, not nums. The slice assignment then replaces positions 1 through 2 in nums with [2, 3, 99], so the final list is [1, 2, 3, 99, 4].
Why the other choices are weaker:
nums.What this tests: Slicing creates a new list, while slice assignment mutates the target list.
Related topics: Lists; Slices; Mutation; Assignment
Topic: Exception order and finally
What is printed by this code?
1try:
2 value = int("ten")
3except ValueError:
4 print("value")
5except Exception:
6 print("exception")
7else:
8 print("else")
9finally:
10 print("done")
value and then doneexception and then doneelse and then donedone onlyBest answer: A
Explanation: int("ten") raises ValueError. The first matching except block runs, so value is printed. The else block does not run because an exception occurred, and the finally block runs regardless.
Why the other choices are weaker:
ValueError handler appears before the broader Exception handler.try block to finish without an exception.except ValueError block.What this tests: Specific exception matching, else behavior, and guaranteed finally execution.
Related topics: Exceptions; ValueError; else; finally; Handler order
Topic: Class and instance attributes
What is printed by this code?
1class Counter:
2 total = 0
3
4 def __init__(self):
5 Counter.total += 1
6 self.total = 10
7
8a = Counter()
9b = Counter()
10print(Counter.total, a.total, b.total)
2 10 1010 10 102 2 2AttributeError.Best answer: A
Explanation: Counter.total is a class attribute and is incremented twice, once for each instance. Each instance also receives its own self.total value of 10, which shadows the class attribute when accessed through that instance.
Why the other choices are weaker:
self.total overwrites the class attribute.What this tests: Class attributes, instance attributes, attribute lookup, and constructor side effects.
Related topics: Classes; Instances; Attributes; Constructors; Shadowing
Topic: File processing with local error handling
A script reads a CSV file where some rows contain invalid integers. The requirement is to skip only malformed rows, keep processing valid rows, and close the file reliably. Which pattern is strongest?
except Exception and ignore every error.with open(...) block and catch ValueError around the per-row conversion that can fail.int() on it once.Best answer: C
Explanation: The with block handles reliable file closing, and catching ValueError near the conversion lets the script skip only rows that fail parsing. This preserves useful rows and avoids hiding unrelated errors from the rest of the program.
Why the other choices are weaker:
What this tests: Context managers, file lifetime, narrow exception handling, and practical data-processing control flow.
Related topics: Files; Context managers; ValueError; CSV parsing; Error handling
Tech Exam Lexicon and IT Mastery are independent study tools. They are not affiliated with, endorsed by, or sponsored by Python Institute or any certification body.