PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
An inventory script defines `def add_stock(item, quantity, *restock_dates):` and is called as `add_stock('bolt', 40, '2024-01-05', '2024-02-11')`. Inside the function, the developer wants to count how many restock dates were supplied. Which expression correctly reports that count?
⚠ Common exam trap
The trap here is treating the packed parameter as if it had a length attribute or as if measuring one element summarized the whole collection, when only len on the tuple gives the total count.
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
✓
len(restock_dates)
The starred parameter packs all surplus positional arguments into a tuple, so the number of restock dates equals the length of that tuple. Calling the built-in len on the packed tuple gives the exact count of extra arguments received, while indexing or attribute-style length access either measures the wrong thing or fails outright.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
len(restock_dates[0])
Why it's wrong here
Indexing at position 0 retrieves only the first restock date string, and taking its length yields the number of characters in that date, not the number of dates supplied. For '2024-01-05' the result would be 10, which is meaningless for inventory counting. The whole tuple must be measured, not one of its elements.
- ✓
len(restock_dates)
Why this is correct
A parameter prefixed with an asterisk collects any extra positional arguments into a tuple. Here restock_dates becomes ('2024-01-05', '2024-02-11'), so len(restock_dates) returns 2. Because it is a tuple, it supports len, indexing, and iteration, which is exactly how variadic functions inspect the surplus arguments they received.
- ✗
restock_dates.length
Why it's wrong here
Python tuples have no length attribute; the size of a sequence is obtained through the built-in len function. Accessing .length raises AttributeError, which would crash the inventory script. This distractor reflects confusion with languages that expose a length property, but Python's sequence protocol standardizes on len instead.
- ✗
restock_dates.count
Why it's wrong here
This references the bound method object itself rather than calling it, so it would not produce a count. Even if invoked, count requires a value to search for, such as a specific date, and would only report occurrences of that one date. The developer needs the total number of dates, which the tuple's length provides directly.
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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.