The answer is AttributeError. This error occurs because the code attempts to access an undefined attribute `balance` on a `BankAccount` instance, yet the class only defines `__init__` and `deposit` methods without ever setting a `balance` attribute. In Python, when you try to access a missing attribute on an object, the interpreter raises an `AttributeError` rather than returning `None` or a default value—this is a fundamental rule of Python’s attribute lookup mechanism. On the PCAP exam, this concept tests your understanding of object attribute management and error handling, often appearing in questions that trick you into assuming attributes are automatically created by method names. A common trap is thinking that a method named `deposit` implies a `balance` attribute exists, but Python requires explicit assignment in `__init__` or elsewhere. Memory tip: “No attribute, no default—AttributeError is the result.”
PCAP Object-Oriented Programming Practice Question
This PCAP practice question tests your understanding of object-oriented programming. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
AttributeError
Option A is correct because the code attempts to access the attribute `balance` on an instance of the `BankAccount` class, but the class defines only `__init__` and `deposit` methods, and no `balance` attribute is ever set. In Python, accessing a non-existent attribute raises an `AttributeError`, not returning a default value or silently failing.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✓
AttributeError
Why this is correct
Name mangling prevents direct access to __balance.
Related concept
Read the scenario before looking for a memorised answer.
✗
0
Why it's wrong here
No, it raises an error.
✗
None
Why it's wrong here
Error is raised, not None.
✗
100
Why it's wrong here
Direct access is not possible due to name mangling.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Python Institute often tests the misconception that accessing a missing attribute in Python returns a default value like `None` or `0`, when in fact it raises an `AttributeError` unless the class defines `__getattr__` or `__getattribute__`.
Detailed technical explanation
How to think about this question
Under the hood, Python objects store attributes in a per-instance dictionary (`__dict__`). When you access `obj.balance`, Python looks up `'balance'` in that dictionary; if not found, it checks the class and its bases via the MRO. If still not found, Python raises `AttributeError`. This is a fundamental difference from languages like Java or C++ where accessing a missing field is a compile-time error. In real-world banking applications, failing to initialize a balance attribute could lead to runtime crashes if not handled with `hasattr()` or `try/except`.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A company's IT admin needs to give a contractor read-only access to production logs without sharing account credentials. Using role-based access control (RBAC) and temporary scoped permissions — not a permanent shared password — is the correct pattern. Questions like this test whether you can apply least-privilege access across cloud identity services.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Object-Oriented Programming — This question tests Object-Oriented Programming — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: AttributeError — Option A is correct because the code attempts to access the attribute `balance` on an instance of the `BankAccount` class, but the class defines only `__init__` and `deposit` methods, and no `balance` attribute is ever set. In Python, accessing a non-existent attribute raises an `AttributeError`, not returning a default value or silently failing.
What should I do if I get this PCAP question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Refer to the exhibit. What will happen when the code is executed?
medium
A.It prints None
B.It raises a TypeError
✓ C.It raises an AttributeError
D.It prints 10
Why C: The code attempts to call a method or access an attribute that does not exist on the object. In Python, when you try to access an attribute or method that is not defined on an object, an AttributeError is raised. Option C is correct because the exhibit shows an attempt to call a non-existent method or attribute on an instance, which triggers AttributeError.
Last reviewed: Jun 30, 2026
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.