PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
Consider the following code:
def foo(x, y):
return x * yresult = foo(y=2, 3)
What is the error?
⚠ Common exam trap
The PCEP exam often tests the rule that positional arguments must precede keyword arguments in a function call, and the trap here is that candidates may mistakenly think the error is about missing arguments or invalid keyword usage, rather than the ordering violation.
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
✓
A positional argument follows a keyword argument.
In Python, when calling a function, all positional arguments must appear before any keyword arguments. The call `foo(y=2, 3)` violates this rule by placing a positional argument (`3`) after a keyword argument (`y=2`), which raises a SyntaxError. This is enforced by Python's parser to avoid ambiguity in argument binding.
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 function requires at least one argument but none provided.
Why it's wrong here
Python raises a SyntaxError before any call occurs: a positional argument cannot follow a keyword argument in the same call, so `foo(y=2, 3)` is invalid syntax. It tempts because missing-argument errors do exist, but that is a TypeError raised at call time, not this parse failure.
- ✓
A positional argument follows a keyword argument.
Why this is correct
Python evaluates arguments left to right, so once y=2 is supplied as a keyword argument, the following positional 3 cannot be matched to a parameter. Python raises a SyntaxError because a positional argument follows a keyword argument.
- ✗
Keyword arguments cannot be used in function calls.
Why it's wrong here
Keyword arguments are valid in Python calls; the actual error is positional argument 3 following keyword argument y=2, which raises SyntaxError. Assuming keywords are disallowed is tempting because mixing both styles looks unusual, but ordering, not keyword use, causes the failure.
- ✗
The function definition has too many parameters.
Why it's wrong here
The definition `def foo(x, y)` is valid; the fault lies in the call, where positional `3` follows keyword `y=2`, which Python rejects as a SyntaxError. It tempts because parameter-count mismatches do raise TypeError, but here both parameters are declared and supplied.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.