Limited-Time Offer: Enjoy 50% Savings! - Ends In 0d 00h 00m 00s Coupon code: 50OFF
Welcome to QA4Exam

Free practice questions with explanations

Python Institute PCAP-31-03 Dumps 2026 with Free Practice Questions and Answers

Practise for the Certified Associate in Python Programming Exam with 11 original questions, each with an answer and explanation.

Topics: Object-Oriented Programming, Exceptions, Modules And Packages, Strings and 1 more.

Includes single answer, multiple answers, drag and drop, dropdown and order list. A new question is added every 15 days.

PCAP-31-03 Practice Set Details

Exam Code
PCAP-31-03
Questions On This Page
11
Exam Topics Covered
5 of 5
Question Types
5
Newest Question
New Question
Every 15 days
Full Question Set
154
Certification
Certified Associate in Python Programming
11 questions

Python Institute PCAP-31-03 Exam Questions and Answers by Topic

Modules and Packages

2 practice questions on this topic

Question 1

Added

Single Answer

A team ships a Python application as a package named `acme`, with a nested module `acme.reports.csv`. During development, a script launched from the repository root imports `csv` successfully, but the deployed program fails when it tries to import a helper using `from reports import formatter`. The helper is located beside `csv.py` under `acme/reports`, and the package directories contain `__init__.py` files. The application must be runnable from different working directories without modifying global environment settings. Which change best fixes the import while preserving the package structure?

Correct answer: A

Using `from acme.reports import formatter` names the module through its package hierarchy, so its resolution does not depend on the process working directory. Adding a repository path to `sys.path` couples deployment to a particular layout and still leaves the import ambiguous. Renaming the directory discards the existing package namespace rather than fixing qualification. Moving the helper to the working directory makes the import dependent on how the program is launched.

Question 2

Added

Drag And Drop

A diagnostic script runs across several Python 3 installations and records a small set of environment facts for support. The team needs the active Python implementation name, the operating-system family, and the Python version as a tuple; it wants to use documented functions from the standard `platform` module. Match each required fact to the appropriate function.

Drag each item onto its matching target. On a phone: tap an item, then tap a target.

Active interpreter implementation name
Operating-system family name
Python version components as a tuple
`platform.python_implementation()`
`platform.system()`
`platform.python_version_tuple()`
Correct answer:
  • Active interpreter implementation name → `platform.python_implementation()`
  • Operating-system family name → `platform.system()`
  • Python version components as a tuple → `platform.python_version_tuple()`

`platform.python_implementation()` identifies the implementation, such as CPython. `platform.system()` returns the operating-system name, while `platform.python_version_tuple()` returns the Python version components as strings in a tuple. `platform.platform()` produces a descriptive platform string rather than the requested focused result. `platform.machine()` describes the machine architecture, and `platform.version()` reports the operating-system version, not the Python version tuple.

Exceptions

2 practice questions on this topic

Question 3

Added

Single Answer

A data-import utility accepts a filename and converts each line to an integer. A malformed record should be reported with its original conversion error available for diagnostics, while a missing file should be handled separately. The utility should print a success message only when the file was opened and every line was converted; it must not suppress unrelated programming errors. Which structure best meets these requirements?

Correct answer: C

Binding the conversion failure with `except ValueError as e` preserves the exception object and its arguments for diagnostics; a separate `OSError` handler distinguishes file failures. An `else` suite runs only if the protected operations complete without an exception, which makes it appropriate for the success message. Catching broad `Exception` also hides unrelated defects, and `finally` runs on failure. Combining the two expected errors loses the required distinction. Assertions are not a substitute for validating external input.

Question 4

Added

Single Answer

A service validates a numeric configuration value before starting. The value must be strictly positive, and failure should raise an `AssertionError` carrying the supplied configuration name so a caller can identify which setting failed. The check is intended as a development invariant, not as production input validation; ordinary malformed user input is handled elsewhere. Which statement implements the specified check?

Correct answer: C

The assertion condition is true for every strictly positive value. When it is false, Python raises `AssertionError` and uses the supplied message expression, here `name`, as its argument. Constructing `AssertionError` with a Boolean condition does not perform a check and raises unconditionally. The conditional `raise` syntax shown is not valid Python syntax and would raise the wrong exception even if rewritten. The inverse assertion succeeds for invalid values and fails for valid ones.

Strings

2 practice questions on this topic

Question 5

Added

Multiple Answers

A telemetry service receives Python `str` values containing arbitrary Unicode text and must create a stable, case-insensitive key for each value. The key must remove leading and trailing whitespace, collapse each run of internal whitespace to one ASCII space, and preserve non-ASCII letters rather than converting them to escape sequences. The input strings must remain unchanged because other code retains references to them. Which two operations together meet the requirements? (Choose two.)

Correct answer: A, C

`strip()` removes leading and trailing whitespace, and `lower()` returns a lowercased string without mutating the original. Splitting on whitespace without an explicit separator treats runs of whitespace as separators; joining the pieces with one space collapses those runs and preserves Unicode characters. ASCII encoding cannot represent arbitrary non-ASCII text. Strings do not support item or slice assignment because they are immutable. `repr()` produces a representation for debugging, not a normalized key, and removing quotes does not reliably undo its escaping.

Question 6

Added

Single Answer

A log parser searches a line for the final occurrence of the marker `END:` and then extracts the text after it. Some lines do not contain the marker; in those cases, the parser must distinguish absence from a marker at the start of the line. The input is a string, and the parser should avoid raising an exception for missing markers. Which expression provides the required position check?

Correct answer: C

`rfind()` returns the highest index of the matching substring, or `-1` when it is absent. Testing against `-1` correctly accepts a marker at index zero and selects the final occurrence when there are several. `index()` raises `ValueError` when there is no match. `find()` selects the first occurrence rather than the last. Requiring a position greater than zero incorrectly rejects a marker at the beginning of the line.

Miscellaneous (List Comprehensions, Lambdas, Closures, and I/O Operations)

1 practice question on this topic

Question 7

Added

Single Answer

A command-line utility must open a user-supplied path for reading. If the path does not exist, it should print a concise message that includes the operating-system error number; other I/O errors must not be mislabeled as a missing file. The program should use Python's standard exception information rather than inspect the human-readable message, which can vary by platform. Which handling approach is best?

Correct answer: C

Opening a nonexistent path raises an `OSError` whose `errno` is `errno.ENOENT`. Checking that structured value identifies the missing-path case independently of platform-specific message wording, while re-raising other errors avoids misclassification. Searching the text of a broad exception is fragile and can swallow unrelated failures. Treating every I/O error as a missing file is inaccurate; in Python 3, `IOError` is an alias of `OSError` and does not narrow the failures. An assertion is not suitable for handling expected external I/O conditions and may be disabled.

Object-Oriented Programming

4 practice questions on this topic

Question 8

Added

Single Answer

A library class stores an account balance in an instance attribute named `__balance`. A subclass is written by a different team and defines its own `__balance` attribute for a separate calculation. The subclass developer assumes both names refer to the same storage because they have the same spelling in source code. The library must retain its internal state without forbidding subclass-specific state or changing the public API. Which explanation best describes the resulting behavior?

Correct answer: A

A name beginning with at least two underscores and not ending with at least two underscores is class-name-mangled. Thus the base class and subclass declarations become distinct attribute names, reducing accidental collisions while still allowing the object to hold both values. Python does not dynamically merge same-spelled private attributes. A subclass attribute does not replace the differently mangled base attribute, and assigning the subclass's own attribute does not inherently raise `AttributeError`.

Question 9

Added

Multiple Answers

A simulation framework accepts objects from third-party code. A component must be treated as a `Sensor` when it is an instance of `Sensor` or any subclass, including a class that inherits from `Sensor` through multiple inheritance. The framework must also report the actual class of each object without relying on a user-overridden `__str__` method. Which two approaches satisfy these requirements? (Choose two.)

Correct answer: B, E

`isinstance(obj, Sensor)` accepts instances of `Sensor` and instances of its subclasses, including subclasses formed through multiple inheritance. `obj.__class__.__name__` reports the runtime class name without calling the object's `__str__` method. An identity comparison with `type()` accepts only objects whose exact type is `Sensor`. `str(obj)` can be replaced by an arbitrary representation. `Sensor.__bases__` lists direct base classes of the class, not the type of a particular object or the complete descendant hierarchy.

Question 10

Added

Order List

A developer is creating a subclass that overrides a method but must preserve the base-class initialization and behavior. The subclass constructor needs to establish its own attribute only after the base constructor has initialized the inherited state. Arrange the steps in the order they must be performed to implement and use this design.

Drag the steps into the correct order, or use the arrows.

  1. Initialize the subclass-specific instance attribute.
  2. Call the base constructor through `super().__init__` with the required arguments.
  3. Instantiate the subclass and invoke the overridden method.
  4. Define the subclass with the base class in its inheritance list.
  5. Define the subclass constructor with `self` and any required arguments.
Correct answer:
  1. Define the subclass with the base class in its inheritance list.
  2. Define the subclass constructor with `self` and any required arguments.
  3. Call the base constructor through `super().__init__` with the required arguments.
  4. Initialize the subclass-specific instance attribute.
  5. Instantiate the subclass and invoke the overridden method.

The class declaration establishes the inheritance relationship before its methods are defined. The constructor then calls the base constructor so inherited state is initialized before subclass state is added. After both layers of initialization are complete, an instance can be created and its overridden method invoked. Initializing subclass state before the base constructor would violate the stated sequencing requirement. Instantiating before the class and constructor exist is not possible.

Question 11

Added

Dropdown

A reporting library wants every instance to start with an independent list of warnings, while each instance should share the same fixed severity label unless explicitly overridden on that instance. Complete the class definition using the appropriate instance and class attribute placement.

Choose the correct value for each blank.

class Report:
= "normal"
def __init__(self):
self. = []
Correct answer:

class Report:
severity = "normal"
def __init__(self):
self.warnings = []

A class attribute such as `severity` provides a shared default lookup for instances; an instance can still override it by assigning `self.severity`. The list must be assigned as `self.warnings` inside `__init__` so each instance receives its own list rather than sharing mutable state. Writing `self.severity` in the class body is invalid syntax. The other first-blank spellings define different attributes or are not valid class attribute declarations here. The alternative second-blank values either put the list on the class or name the wrong field.

More Practice Questions

Get the Full Python Institute PCAP-31-03 Dumps as PDF and Practice Test

11 questions are free on this page and the full set has 154. It comes as a PDF and an online practice test, with 90 days of free updates.