Courseiva
Functions, Tuples, Dictionaries and ExceptionseasyMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer writes a function that should return the sum of two numbers, but the code returns 0 instead. What is the most likely cause?

def add(a, b):

result = a + b

print(add(3, 4))

⚠ Common exam trap

Python Institute often tests the distinction between computing a value inside a function and actually returning it — the trap here is that candidates see `result = a + b` and assume the sum is automatically output, missing the critical absence of the `return` statement.

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

The function does not have a return statement.

The function `add` computes `a + b` and assigns it to `result`, but lacks a `return` statement. In Python, a function without an explicit `return` automatically returns `None`. When `print(add(3, 4))` is executed, it prints `None`, not the sum. The question states the code returns 0, which is a common misreading — the actual output is `None`, but the core issue is the missing `return`.

Answer analysis

Option-by-option breakdown

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

  • The function is not defined before the call.

    Why it's wrong here

    The function is defined before the print statement.

  • The variable 'result' is not defined.

    Why it's wrong here

    The variable is defined and assigned inside the function.

  • The function parameters are of incompatible types.

    Why it's wrong here

    Both parameters are integers, no type conflict.

  • The function does not have a return statement.

    Why this is correct

    The function computes the sum but does not return it, returning None instead.

About these practice questions

This PCEP question is part of Courseiva's 498-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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.