Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer is writing a function that should accept any number of positional arguments and return their sum. Which function definition correctly achieves this?

⚠ Common exam trap

Many exam-takers confuse *args with **args, or incorrectly unpacking the tuple when passing to sum, which would cause a TypeError.

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 sum_all(*args): return sum(args)

The *args parameter collects any number of positional arguments into a tuple, which can then be summed using the built-in sum function. The other options either accept only a single iterable, collect keyword arguments instead, or incorrectly unpack the tuple when calling sum, leading to errors.

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 sum_all(*args): return sum(*args)

    Why it's wrong here

    While *args collects positional arguments into a tuple, using sum(*args) attempts to unpack the tuple as separate arguments to sum. The built-in sum expects an iterable and an optional start value, so this would raise a TypeError if more than one argument is provided. The correct usage is sum(args).

  • ✓

    def sum_all(*args): return sum(args)

    Why this is correct

    The *args syntax collects all positional arguments into a tuple named args, which can then be passed to the built-in sum function. This allows the function to accept zero or more arguments. It is the standard way to define a variadic function in Python.

  • ✗

    def sum_all(**args): return sum(args)

    Why it's wrong here

    The **args syntax collects keyword arguments into a dictionary, not positional arguments. Passing positional arguments would cause a TypeError. Also, sum cannot operate on a dictionary directly, as it would attempt to sum the keys, leading to incorrect behavior.

  • ✗

    def sum_all(args): return sum(args)

    Why it's wrong here

    This definition expects a single argument named args, which must be an iterable. If called with multiple arguments, it raises a TypeError. It does not support variadic arguments, so it fails the requirement of accepting any number of positional arguments.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.