Courseiva
← Back to Certified Associate Python Programmer PCAP questions

Scenario-based practice

Refer to the Exhibit Practice Questions

Practise Certified Associate Python Programmer PCAP practice questions — original exam-style scenarios covering every exam domain, with detailed explanations, wrong-answer analysis, and common exam traps.

15
scenario questions
PCAP
exam code
Python Institute
vendor

Scenario guide

How to approach refer to the exhibit practice questions

Practise exhibit-style questions that ask you to read a topology, table, command output or diagram before choosing the best answer.

Quick answer

Exhibit-style questions test whether you can read a topology, command output, diagram or table before choosing the best answer.

How to extract the relevant detail from an exhibit.

How topology, command output or routing information affects the answer.

How to avoid answering from memory before reading the evidence.

How to map the exhibit back to the exam objective.

Related practice questions

Related PCAP topic practice pages

Scenario questions usually connect to one or more exam topics. Use these links to review the underlying concepts behind the scenario.

Practice set

Practice scenarios

Question 1hardmultiple choice
Full question →

Refer to the exhibit. What is the root cause of the error?

Exhibit

class MyClass:
    def __init__(self):
        self.name = "test"
obj = MyClass()
print(obj.age)
Question 2easymultiple choice
Full question →

Refer to the exhibit. If the file config.cfg exists but the user does not have read permission, what will be printed?

Exhibit

try:
    with open('config.cfg', 'r') as f:
        data = f.read()
except FileNotFoundError:
    print('File not found')
except PermissionError:
    print('Permission denied')
Question 3hardmultiple choice
Full question →

Refer to the exhibit. A developer ran the script and saw the above traceback. The intended behavior was to load a JSON configuration file, and if the file is missing, create a default config. What is the most likely root cause of the second exception (NameError)?

Exhibit

Traceback (most recent call last):
  File "app.py", line 9, in <module>
    with open("config.json", "r") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 11, in <module>
    config = json.load(f)
             ^^^^^^^^^^^
NameError: name 'json' is not defined
Question 4mediummultiple choice
Full question →

Refer to the exhibit. A developer is writing a script to read this JSON configuration file. The script should write the logging configuration to a separate file called 'logging.conf'. Which file mode should be used to create the file if it doesn't exist, and overwrite it if it does?

Exhibit

{
  "logging": {
    "level": "DEBUG",
    "file": "/var/log/app.log"
  },
  "database": {
    "host": "localhost",
    "port": 5432
  }
}
Question 5mediummultiple choice
Full question →

Refer to the exhibit. Which of the following is the most likely cause of this error?

Exhibit

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from mypackage import mymodule
ImportError: cannot import name 'mymodule' from 'mypackage' (unknown location)
Question 6mediummultiple choice
Full question →

Refer to the exhibit. Given the project structure, which of the following import statements in main.py would cause an ImportError?

Exhibit

Exhibit:
Project structure:
main.py
utils/
    __init__.py
    helpers.py
    strings/
        __init__.py
        format.py

# main.py
from utils.helpers import greet
from utils.strings.format import bold

Refer to the exhibit. What is the output? (Note: actual MRO may vary; choose the one that matches Python 3 C3 linearization.)

Exhibit

class A:
    def method(self):
        return "A"

class B(A):
    def method(self):
        return "B"

class C(A):
    def method(self):
        return "C"

class D(B, C):
    pass

print(D.__mro__)
Question 8hardmultiple choice
Full question →

Refer to the exhibit. What is printed?

Exhibit

class Cache:
    def __init__(self, func):
        self.func = func
        self.cache = {}
    def __call__(self, *args):
        if args in self.cache:
            return self.cache[args]
        result = self.func(*args)
        self.cache[args] = result
        return result

@Cache
def add(a, b):
    return a + b

print(add(1, 2))
print(add(1, 2))
Question 9mediummultiple choice
Full question →

Refer to the exhibit. Which of the following fixes the error?

Exhibit

Error log:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print('Hello' + 5)
TypeError: can only concatenate str (not "int") to str

Refer to the exhibit. A Python script uses the following code to load the policy. However, it fails with a JSONDecodeError. What is the most likely cause? ```python

import json
with open('policy.json', 'r') as f:

policy = json.load(f) ```

Exhibit

{
  "rules": [
    {"action": "allow", "src": "10.0.1.0/24"},
    {"action": "deny", "src": "0.0.0.0/0"},
  ]
}
Question 11easymultiple choice
Full question →

What is the output of the code in the exhibit?

Exhibit

Refer to the exhibit.

name = "Alice"
age = 30
print(f"{name} is {age} years old.")
Question 12mediummultiple choice
Full question →

Refer to the exhibit. A developer runs 'pip install pandas==2.0.0' but gets an error stating that the required version is not available. Which command should be used to list all available versions of pandas?

Exhibit

Exhibit:
$ pip list
Package    Version
---------- -------
numpy      1.24.0
pandas     1.5.3
pip        22.0.4
Question 13easymultiple choice
Full question →

Refer to the exhibit. What happens when the last line is executed?

Exhibit

class MyClass:
    __slots__ = ('name', 'age')
    def __init__(self, name, age):
        self.name = name
        self.age = age

obj = MyClass('John', 30)
obj.city = 'New York'
Question 14mediummultiple choice
Full question →

Refer to the exhibit. Which of the following correctly shows the MRO of class D?

Exhibit

class A:
    def method(self):
        return 'A'
class B(A):
    def method(self):
        return 'B'
class C(A):
    def method(self):
        return 'C'
class D(B, C):
    pass

print(D.mro())
Question 15hardmultiple choice
Full question →

Refer to the exhibit. What is the output of the last line?

Exhibit

$ cat employee.py
class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.__salary = salary
    def get_salary(self):
        return self.__salary
    def set_salary(self, new_salary):
        if new_salary > 0:
            self.__salary = new_salary
$ python3 -c "from employee import Employee; e = Employee('John', 50000); print(e.get_salary()); print(e.__dict__)"

These PCAP practice questions are part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style PCAP questions with detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics.