Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

What does the following code print?

x = 10

if x > 5:
    if x > 15:
        print("A")

else:

print("B")

else:

print("C")

⚠ Common exam trap

Python Institute often tests the misconception that the outer else (printing 'C') will execute when the inner condition fails, but candidates must remember that the outer else only runs if the outer condition is false.

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

✓

B

The code first checks if x > 5, which is true because x = 10. Then it checks if x > 15, which is false, so the else branch of the inner if-else executes, printing 'B'. The outer else is skipped entirely.

Answer analysis

Option-by-option breakdown

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

  • ✗

    No output

    Why it's wrong here

    The outer condition x > 5 is true, so the else branch is skipped and the inner if-else executes, printing B. No output would require both conditions to fail silently, which cannot happen here. It tempts when candidates assume a nested if suppresses output, but it would be correct only if neither branch contained a print statement.

  • ✗

    C

    Why it's wrong here

    C prints only when x is not greater than 5, but x equals 10, so the outer if is true and its else is skipped. It tempts because C is the outer else's output, and it would be correct if the initial value of x were 5 or lower.

  • ✓

    B

    Why this is correct

    x equals 10, so the outer condition x > 5 is true and the inner block runs. The inner test x > 15 is false, so the else branch executes, printing B. The outer else is skipped entirely.

  • ✗

    A

    Why it's wrong here

    A requires x > 15 inside the outer true branch, but x is 10, so the inner else prints B instead. It tempts because A is the first print encountered when reading top-down, and it would be correct if x were assigned a value above 15.

About these practice questions

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

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.