Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer is writing a Python function that must accept any number of positional arguments and return their sum. The function should also work when called with zero arguments. Which function definition correctly achieves this?

⚠ Common exam trap

A common mix-up: candidates confuse the parameter syntax *nums (which collects arguments) with the call syntax sum(*nums) (which unpacks), leading to a TypeError when the tuple is empty or when elements are not iterable.

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

The function must handle any number of positional arguments, including zero. Using *nums in the function definition collects arguments into a tuple, and sum() correctly adds them, returning 0 for an empty tuple. Other options either restrict the number of arguments or incorrectly unpack the tuple.

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(nums): return sum(nums)

    Why it's wrong here

    This definition expects exactly one positional argument, nums. If the function is called with zero arguments or more than one argument, Python raises a TypeError. It does not support arbitrary positional arguments, so it fails the scenario's requirement.

  • ✗

    def total(nums=0): return sum(nums)

    Why it's wrong here

    This defines a single parameter with a default value of 0. It cannot accept multiple positional arguments; calling with two or more raises TypeError. Also, sum(0) raises TypeError because 0 is not iterable. It does not meet the requirement.

  • ✓

    def total(*nums): return sum(nums)

    Why this is correct

    Using *nums in the parameter list collects all positional arguments into a tuple named nums, which works even when no arguments are passed (nums becomes an empty tuple). The built-in sum() then returns 0 for an empty tuple, satisfying the zero-argument requirement.

  • ✗

    def total(*nums): return sum(*nums)

    Why it's wrong here

    Here *nums in the call to sum() unpacks the tuple into separate arguments. If nums is empty, sum() receives no arguments and raises a TypeError. Also, sum() expects an iterable, not unpacked positional arguments, so this fails even with elements.

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.