- A
The dictionary does not have an 'action' key
Why wrong: It does have the key.
- B
The developer used rule['action'] instead of rule.get('action')
Why wrong: Both work; get is not required.
- C
The for loop syntax is incorrect; it should be for rule in rules:
Why wrong: Syntax is correct.
- D
The developer used rule('action') instead of rule['action']
Dictionary access uses square brackets or get method.
Quick Answer
The answer is that the developer used `rule('action')` instead of `rule['action']`, which is the most likely cause of the script failing to print any output. In Python, dictionary access requires square brackets—like `rule['action']`—because dictionaries are key-value mappings accessed via indexing syntax, not function-call syntax. Using parentheses, as in `rule('action')`, attempts to call the dictionary object itself as a function, which raises a `TypeError` and halts execution entirely, meaning the loop never reaches the `print` statement even though `'allow'` rules exist. On the Certified Entry-Level Python Programmer PCEP exam, this question tests your understanding of fundamental dictionary operations and common syntax errors; it’s a classic trap where learners confuse parentheses (used for function calls) with brackets (used for indexing). A reliable memory tip: think of square brackets as “keys to the castle”—you use them to unlock a dictionary’s value, while parentheses are reserved for calling functions or methods.
PCEP Control Flow, Loops, Lists and Logic Practice Question
This PCEP practice question tests your understanding of control flow, loops, lists and logic. This is a configuration task: choose the command set that satisfies every stated requirement. Small differences — like 'secret' vs 'password' or 'transport input ssh' vs 'all' — change whether the answer is correct. 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.
You are working on a network automation script that reads a configuration file containing firewall rules. Each rule is a dictionary with keys 'source_ip', 'dest_ip', 'action'. The script must iterate over the rules and print all rules where action is 'allow'. However, the script is not printing any output even though there are allow rules in the file. The code snippet is:
rules = [{'source_ip':'10.0.0.1','dest_ip':'10.0.0.2','action':'allow'},
{'source_ip':'10.0.0.2','dest_ip':'10.0.0.3','action':'deny'}]
for rule in rules:
if rule('action') == 'allow':
print(rule)What is the most likely cause of the problem?
Clue words in this question
Noticing these words before you look at the options changes how you read each choice.
Clue:
"most likely"Why it matters: Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
The developer used rule('action') instead of rule['action']
Option D is correct because in Python, dictionary values are accessed using square brackets (e.g., rule['action']) or the .get() method, not parentheses. Using parentheses like rule('action') attempts to call the dictionary as a function, which raises a TypeError and prevents the script from executing, so no output is printed even though allow rules exist.
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.
- ✗
The dictionary does not have an 'action' key
Why it's wrong here
It does have the key.
- ✗
The developer used rule['action'] instead of rule.get('action')
Why it's wrong here
Both work; get is not required.
- ✗
The for loop syntax is incorrect; it should be for rule in rules:
Why it's wrong here
Syntax is correct.
- ✓
The developer used rule('action') instead of rule['action']
Why this is correct
Dictionary access uses square brackets or get method.
Clue confirmation
The clue word "most likely" in the question point toward this answer.
Related concept
Read the scenario before looking for a memorised answer.
Common exam traps
Common exam trap: answer the scenario, not the keyword
The trap here is that candidates may overlook the subtle difference between parentheses and brackets for dictionary access, assuming both work similarly, but Python strictly requires square brackets for key lookup.
Detailed technical explanation
How to think about this question
In Python, dictionaries are mapping objects that implement the __getitem__ method for bracket access (e.g., d['key']) and the __call__ method is not defined for dictionaries, so d('key') raises a TypeError. This is a common syntax error where parentheses (used for function calls) are confused with brackets (used for indexing or key access). In real-world network automation scripts, such a mistake would cause the script to crash immediately, preventing any processing of firewall rules.
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 security administrator must allow nursing staff to reach a patient records server while blocking access from the guest Wi-Fi VLAN. After applying an extended ACL, traffic is still blocked from nursing workstations. The ACL was applied outbound instead of inbound on the wrong interface. Questions like this test ACL direction and placement rules.
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.
- →
Control Flow, Loops, Lists and Logic — study guide chapter
Learn the concepts, then practise the questions
- →
Control Flow, Loops, Lists and Logic practice questions
Targeted practice on this topic area only
- →
All PCEP questions
510 questions across all exam domains
- →
Certified Entry-Level Python Programmer PCEP study guide
Full concept coverage aligned to exam objectives
- →
PCEP practice test guide
How to use practice tests most effectively before exam day
Related practice questions
Related PCEP practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
Computer Programming and Python Fundamentals practice questions
Practise PCEP questions linked to Computer Programming and Python Fundamentals.
Data Types, Variables, Basic I/O and Operators practice questions
Practise PCEP questions linked to Data Types, Variables, Basic I/O and Operators.
Control Flow, Loops, Lists and Logic practice questions
Practise PCEP questions linked to Control Flow, Loops, Lists and Logic.
Functions, Tuples, Dictionaries and Exceptions practice questions
Practise PCEP questions linked to Functions, Tuples, Dictionaries and Exceptions.
PCEP fundamentals practice questions
Practise PCEP questions linked to PCEP fundamentals.
PCEP scenario practice questions
Practise PCEP questions linked to PCEP scenario.
PCEP troubleshooting practice questions
Practise PCEP questions linked to PCEP troubleshooting.
Practice this exam
Start a free PCEP practice session
Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.
FAQ
Questions learners often ask
What does this PCEP question test?
Control Flow, Loops, Lists and Logic — This question tests Control Flow, Loops, Lists and Logic — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: The developer used rule('action') instead of rule['action'] — Option D is correct because in Python, dictionary values are accessed using square brackets (e.g., rule['action']) or the .get() method, not parentheses. Using parentheses like rule('action') attempts to call the dictionary as a function, which raises a TypeError and prevents the script from executing, so no output is printed even though allow rules exist.
What should I do if I get this PCEP question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Are there clue words in this question I should notice?
Yes — watch for: "most likely". Probability qualifier — the question wants the most probable cause or outcome, not a guaranteed one. Eliminate low-probability options.
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 →
Last reviewed: Jun 11, 2026
This PCEP 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 PCEP 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.