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 output?

Exhibit

class Counter:
    count = 0
    def __init__(self):
        Counter.count += 1
        self.id = Counter.count

c1 = Counter()
c2 = Counter()
print(c1.id, c2.id)
Question 2hardmultiple 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 3hardmultiple choice
Full question →

Refer to the exhibit. What is the output?

Exhibit

Configuration snippet:

import json
policy_string = '{"allow": true, "rate": 100}'
parsed = json.loads(policy_string)
print(parsed['rate'])
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. What is the output of the code?

Exhibit

with open('file.txt', 'r') as f:
    data = f.read()
    print(f.closed)
# Output: False
Question 7mediummultiple 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 9hardmultiple 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 10hardmultiple choice
Full question →

Refer to the exhibit. What is the output?

Exhibit

class Counter:
    count = 0
    def __init__(self):
        Counter.count += 1
    @classmethod
    def get_count(cls):
        return cls.count

c1 = Counter()
c2 = Counter()
print(Counter.get_count())
print(c1.get_count())
print(c2.get_count())
Question 11hardmultiple choice
Full question →

Refer to the exhibit. What is the effect of using 'from None' in the raise statement?

Exhibit

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    raise ValueError("Invalid value")
ValueError: Invalid value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    raise TypeError("Type mismatch") from None
TypeError: Type mismatch
Question 12hardmultiple choice
Full question →

Refer to the exhibit. Which statement about the output is true?

Exhibit

$ python3 -c "class A: pass
a = A()
print(a.__class__.__name__)
print(type(a).__name__)
print(a.__class__.__bases__)
print(type(a).__bases__)"
Question 13mediummultiple choice
Full question →

Refer to the exhibit. What happens when the code is executed?

Exhibit

>>> s = "Hello"
>>> s[1] = "a"
Question 14mediummultiple 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
Question 15mediummultiple choice
Full question →

Refer to the exhibit. What is the output when this code is executed?

Exhibit

class BankAccount:
    def __init__(self, owner, balance=0):
        self.owner = owner
        self.__balance = balance
    def deposit(self, amount):
        self.__balance += amount
    def withdraw(self, amount):
        if amount <= self.__balance:
            self.__balance -= amount
        else:
            print('Insufficient funds')
    def get_balance(self):
        return self.__balance

account = BankAccount('Alice', 100)
print(account.__balance)

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.