Courseiva
Computer Programming and Python FundamentalsmediumMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Consider the following function definition:

def add(a, b):
    return a + b

What is the value of add(3, '4')?

⚠ Common exam trap

The PCEP exam often tests the misconception that Python will implicitly convert types (like treating `'4'` as an integer) or that the `+` operator will concatenate any two values, when in reality it raises a `TypeError` for incompatible types.

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

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Python's `+` operator is not defined for mixed types like `int` and `str`. When `add(3, '4')` is called, Python attempts to evaluate `3 + '4'`, which raises a `TypeError` because it cannot implicitly convert the string to an integer or vice versa. This is a fundamental type safety rule in Python.

Answer analysis

Option-by-option breakdown

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

  • Error due to missing import

    Why it's wrong here

    Not an import issue.

  • '34'

    Why it's wrong here

    Needs both strings.

  • 7

    Why it's wrong here

    Would need conversion.

  • TypeError: unsupported operand type(s) for +: 'int' and 'str'

    Why this is correct

    Incompatible types.

About these practice questions

Courseiva writes every PCEP question from scratch — 498 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

Same concept, more angles

2 more ways this is tested on PCEP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A function is defined as: def add(a, b=5): return a + b What is the result of add(10)?

medium
  • A.10
  • B.5
  • C.15
  • D.Error

Why C: The function `add(a, b=5)` defines a default value of 5 for parameter `b`. When called as `add(10)`, the argument 10 is assigned to `a`, and `b` uses its default value of 5. The function returns `10 + 5 = 15`, making option C correct.

Variation 2. 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))

easy
  • A.The function is not defined before the call.
  • B.The variable 'result' is not defined.
  • C.The function parameters are of incompatible types.
  • D.The function does not have a return statement.

Why D: 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`.

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.