Browse Python Institute Certification Guides

Python Institute PCAP Sample Questions with Explanations

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.

Where these questions fit in the PCAP guide

The sample set below is part of the Python Institute PCAP guide path:

PCAP code-tracing sample questions

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.


Question 1

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)
  • A. [1, 2, 3, 4, 99]
  • B. [1, 2, 3, 99, 4]
  • C. [1, 2, 3, 4]
  • D. The code raises a 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:

  • A treats the operation like a simple append to the original list.
  • C ignores the later slice assignment back into nums.
  • D is wrong because assigning a list to a list slice is valid.

What this tests: Slicing creates a new list, while slice assignment mutates the target list.

Related topics: Lists; Slices; Mutation; Assignment


Question 2

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")
  • A. value and then done
  • B. exception and then done
  • C. else and then done
  • D. done only

Best 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:

  • B ignores that the more specific ValueError handler appears before the broader Exception handler.
  • C would require the try block to finish without an exception.
  • D ignores the matching except ValueError block.

What this tests: Specific exception matching, else behavior, and guaranteed finally execution.

Related topics: Exceptions; ValueError; else; finally; Handler order


Question 3

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)
  • A. 2 10 10
  • B. 10 10 10
  • C. 2 2 2
  • D. The code raises an AttributeError.

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:

  • B assumes assigning self.total overwrites the class attribute.
  • C assumes instance lookup returns the class attribute even after an instance attribute exists.
  • D is wrong because both class and instance attributes are defined before printing.

What this tests: Class attributes, instance attributes, attribute lookup, and constructor side effects.

Related topics: Classes; Instances; Attributes; Constructors; Shadowing


Question 4

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?

  • A. Wrap the entire program in except Exception and ignore every error.
  • B. Open the file without closing it, because Python will eventually clean it up.
  • C. Use a with open(...) block and catch ValueError around the per-row conversion that can fail.
  • D. Convert the whole file to one string and call 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:

  • A hides too much and can mask file, permission, or logic failures.
  • B relies on cleanup timing instead of using a context manager.
  • D ignores the row-by-row nature of the data and fails the requirement.

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

Independent study note

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.

Revised on Sunday, May 10, 2026