Courseiva
Control Flow, Loops, Lists and LogichardMultiple ChoiceObjective-mapped

PCEP Control Flow, Loops, Lists and Logic Practice Question

Exhibit

>>> data = [[1,2], [3,4], [5,6]]
>>> result = []
>>> for row in data:
...     for item in row:
...         if item % 2 == 0:
...             break
...     else:
...         result.append(row)
>>> result
[[1,2], [5,6]]

Refer to the exhibit. What does the else clause of the inner for loop do?

⚠ Common exam trap

The PCEP exam often tests the for-else behavior by making candidates confuse it with the if-else pattern, leading them to think the else runs after every iteration or when a condition is false, rather than understanding it as a 'no-break' indicator.

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

Executes if the inner loop completes without break, meaning no even number in the row.

The else clause of a for loop in Python executes only when the loop completes normally, i.e., without encountering a break statement. In this nested loop, the inner for iterates over elements of a row; if no even number is found (no break), the else triggers, indicating the row has no even numbers. This is why option C is correct.

Answer analysis

Option-by-option breakdown

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

  • Executes if the outer loop condition is false.

    Why it's wrong here

    The else is attached to the inner for, not the outer.

  • Executes if the inner loop is broken, meaning an even number was found.

    Why it's wrong here

    The else clause does not execute when break is hit.

  • Executes if the inner loop completes without break, meaning no even number in the row.

    Why this is correct

    The else clause executes when the loop finishes normally (no break). Here, it appends the row if no even item was found.

  • Executes after each iteration of the inner loop.

    Why it's wrong here

    The else clause executes only after the loop finishes.

About these practice questions

One of 498 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 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.