Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A Python developer is writing a function that takes a list of numbers and returns a new list containing only the numbers that are divisible by 3 or 5. The developer writes the following code:

def filter_numbers(nums):

result = []

for n in nums:
        if n % 3 == 0 or n % 5 == 0:

result.append(n)

return result

Which statement about this function is true?

⚠ Common exam trap

The trap here is thinking that testing zero with modulo raises an error, or misinterpreting the logical operator requirement.

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 correctly returns numbers divisible by 3 or 5, and it does not modify the original list.

The function iterates over the input list, checks each number for divisibility by 3 or 5 using the modulo operator and logical OR, and appends qualifying numbers to a new list. It does not modify the original list, and it correctly implements the specified filtering. The other statements are either incorrect or describe behavior that does not occur.

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 correctly returns numbers divisible by 3 or 5, but it will raise an error if the list contains a zero.

    Why it's wrong here

    Zero is divisible by both 3 and 5 (0 % 3 == 0 and 0 % 5 == 0), so it would be included in the result. The modulo operation with zero as the dividend is valid in Python; it is division by zero that raises an error, but here zero is the number being tested, not the divisor. Therefore, no error occurs.

  • ✗

    The function correctly returns numbers divisible by 3 or 5, but it includes duplicates if the input list has duplicates.

    Why it's wrong here

    The function does return numbers divisible by 3 or 5, but it does not remove duplicates; it simply appends each qualifying number as it iterates. However, the statement says 'but it includes duplicates' which is true, but the question asks for a true statement. This option is partially true but not the most accurate because the function does correctly filter without modifying duplicates, and duplicates are not an error unless specified. The key is to identify the most precise true statement. This option is misleading because it implies duplicates are a problem, but the function's behavior is correct per the requirement.

  • ✓

    The function correctly returns numbers divisible by 3 or 5, and it does not modify the original list.

    Why this is correct

    The function creates a new list called result and appends qualifying numbers to it. It does not alter the original list nums in any way. The filtering condition using modulo and logical OR correctly identifies numbers divisible by 3 or 5. Thus, this statement is true and accurately describes the function's behavior.

  • ✗

    The function correctly returns numbers divisible by 3 or 5, but it uses a logical OR when it should use a logical AND to meet the requirement.

    Why it's wrong here

    The requirement is to include numbers divisible by 3 or 5, so using logical OR is correct. Using AND would only include numbers divisible by both 3 and 5 (i.e., divisible by 15), which is not what is asked. Therefore, the function's use of OR is appropriate and meets the requirement.

About these practice questions

One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.