20+ practice questions focused on Functions, Tuples, Dictionaries and Exceptions — one of the most tested topics on the Certified Entry-Level Python Programmer PCEP exam. Each question includes a detailed explanation so you learn why the right answer is correct.
Start Functions, Tuples, Dictionaries and Exceptions PracticeA server logs are stored as a list of tuples: `logs = [('2024-01-10', 'INFO', 'Started'), ('2024-01-10', 'ERROR', 'Disk full')]`. A developer wants to count how many ERROR logs exist. Which code snippet correctly counts them?
Explanation: Uses a generator expression with `sum()` to count how many tuples in the `logs` list have the second element equal to `'ERROR'`. The expression `log[1] == 'ERROR'` evaluates to `True` (which is treated as 1) or `False` (0) for each tuple, and `sum()` adds them up, giving the correct count of ERROR logs.
A developer writes a function that returns multiple values as a tuple. Which of the following is a valid way to unpack the result into separate variables?
Explanation: When a function returns multiple values as a tuple, Python allows tuple unpacking directly in an assignment statement. The syntax `a, b = func()` automatically unpacks the two-element tuple into the variables `a` and `b`, which is the standard and most Pythonic way to handle such a return.
A Python script processes a list of tuples representing coordinates: `points = [(1,2), (3,4), (5,6)]`. The developer wants to create a dictionary mapping each coordinate to its distance from origin. Which code correctly creates the dictionary?
Explanation: Options B and C are both correct. Option B uses a for loop to compute the Euclidean distance with the square root and inserts it into a dictionary. Option C achieves the same result with a dictionary comprehension. Both produce a dictionary mapping each coordinate tuple to its distance from the origin.
A script uses a dictionary to store counts of words. The code `counts['apple'] += 1` raises a KeyError the first time because the key doesn't exist. Which approach best solves this?
Explanation: `setdefault('apple', 0)` inserts the key with a default value of 0 if it does not exist, then returns the value (0). After that, `counts['apple'] += 1` increments safely. This avoids a KeyError without requiring an explicit check or exception handling, making it the most concise and Pythonic approach for initializing missing dictionary keys.
Which THREE of the following are valid ways to handle an exception in Python?
Explanation: Option A is correct because a `try` statement may combine `except` and `finally` clauses, where `except` handles matching exceptions and `finally` runs cleanup code regardless of whether an exception occurred. Option D is correct because a `try` block with only a `finally` clause is valid Python syntax; it provides guaranteed cleanup but does not itself catch or handle the exception, which then propagates after `finally` executes. Option E is correct because the canonical exception-handling form is `try` with one or more `except` clauses, each optionally specifying an exception type, that catch and process matching exceptions. Option B is not valid because `finally` must be attached to a `try` statement and cannot stand alone. Option C is not valid because an `else` clause in a `try` statement requires at least one preceding `except` clause; `try`/`else` without `except` is a syntax error.
+15 more Functions, Tuples, Dictionaries and Exceptions questions available
Practice all Functions, Tuples, Dictionaries and Exceptions questions1. Baseline your knowledge
Start with 10 questions to gauge your current understanding of Functions, Tuples, Dictionaries and Exceptions. This tells you whether you need a concept refresher or just practice.
2. Review every explanation
For each question — right or wrong — read the full explanation. Understanding why an answer is correct is more valuable than knowing the answer itself.
3. Focus on exam traps
Functions, Tuples, Dictionaries and Exceptions questions on the PCEP frequently use trap wording. Look for subtle differences in answers that test your precision, not just general knowledge.
4. Reach 80% consistently
Do repeated sessions until you score 80%+ three times in a row. Then move to mixed-mode practice to test cross-topic recall under realistic conditions.
The exact number varies per candidate. Functions, Tuples, Dictionaries and Exceptions is tested as part of the Certified Entry-Level Python Programmer PCEP blueprint. Practicing with targeted Functions, Tuples, Dictionaries and Exceptions questions ensures you can handle any format or difficulty that appears.
Yes. Courseiva provides free PCEP practice questions across all exam topics and domains. The platform includes topic-based practice, mock exams, missed-question review, bookmarked questions, and readiness tracking — no account required.
Difficulty is subjective, but Functions, Tuples, Dictionaries and Exceptions is a high-priority exam concept tested in multiple ways — direct recall, scenario analysis, and command-output interpretation. Consistent practice is the best way to build confidence.
Launch a full Functions, Tuples, Dictionaries and Exceptions practice session with instant scoring and detailed explanations.
Start Functions, Tuples, Dictionaries and Exceptions Practice →