Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer writes a function that needs to accept any number of positional arguments and return their sum. Which function definition correctly collects all positional arguments into a tuple named values?

⚠ Common exam trap

Watch out — candidates often confuse *args and **kwargs, assuming that ** collects positional arguments into a tuple when it actually collects keyword arguments into a dictionary.

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

✓

def total(*values):

The *args syntax in a function definition packs all positional arguments into a tuple. Using def total(*values) makes values a tuple containing every positional argument passed. Then sum(values) returns their total. The other definitions either collect keyword arguments into a dictionary, accept only one argument, or add an unnecessary keyword-argument collector that changes the function's behavior.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    def total(*values):

    Why this is correct

    The *values parameter collects any number of positional arguments into a tuple named values. Inside the function, sum(values) can add them. This matches the scenario exactly: total(1, 2, 3) yields values as (1, 2, 3). It also allows zero arguments, in which case values is an empty tuple and sum returns 0.

  • ✗

    def total(**values):

    Why it's wrong here

    The **values syntax collects keyword arguments into a dictionary, not a tuple. If the function is called with positional arguments like total(1, 2, 3), Python raises a TypeError because positional arguments are not accepted. This definition only works for calls such as total(a=1, b=2), which does not match the requirement of summing positional numbers.

  • ✗

    def total(*values, **kwargs):

    Why it's wrong here

    This definition collects positional arguments into the tuple values and keyword arguments into the dictionary kwargs. While it accepts any number of positional arguments, it also allows unexpected keyword arguments that the function does not use. The question asks specifically for collecting positional arguments into a tuple; the extra **kwargs is unnecessary and would silently accept invalid keyword arguments.

  • ✗

    def total(values):

    Why it's wrong here

    This function accepts exactly one positional argument, values. Calling total(1, 2, 3) raises a TypeError because too many positional arguments are given. It cannot accept an arbitrary number of arguments, so it fails the requirement. Even if a tuple is passed as one argument, the function receives a single object, not multiple collected values.

Visual reference

Client Server SYN (seq=100) SYN-ACK (seq=200, ack=101) ACK (ack=201) Connection established — data transfer begins

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.