Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A developer is writing a Python script to compare two numbers. They write the following code:

x = 10 y = 20 result = x > y or x < y and y > 15

print(result)

What is printed?

⚠ Common exam trap

The trap here is assuming that logical operators are evaluated left-to-right without considering that 'and' has higher precedence than 'or'.

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

✓

True

Logical operators in Python follow a specific precedence: 'and' is evaluated before 'or'. Also, comparison operators are evaluated before logical operators. Thus, the expression is grouped as (x > y) or ((x < y) and (y > 15)). Substituting values: (False) or (True and True) = False or True = True. Therefore, the output is True.

Answer analysis

Option-by-option breakdown

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

  • ✓

    True

    Why this is correct

    The expression is evaluated according to operator precedence: comparison operators have higher precedence than logical operators, and 'and' has higher precedence than 'or'. First, x > y is False, x < y is True, and y > 15 is True. Then, x < y and y > 15 evaluates to True and True, which is True. Finally, False or True evaluates to True. So the output is True.

  • ✗

    The output is 10 > 20 or 10 < 20 and 20 > 15, which is not a boolean value.

    Why it's wrong here

    The expression is evaluated to a boolean value, not left as an unevaluated expression. Python does not print the expression itself; it prints the result of evaluating it. The result is a boolean (True or False). This option misunderstands how the print function works with expressions.

  • ✗

    False

    Why it's wrong here

    False would be the result if the expression were evaluated as (x > y or x < y) and y > 15. That would be (False or True) and True, which is True and True, still True. Alternatively, if 'or' had higher precedence, it would be (False or True) and True, also True. So False is not the output under any standard precedence. This option likely results from misinterpreting the logic.

  • ✗

    An error occurs because you cannot mix 'or' and 'and' without parentheses.

    Why it's wrong here

    Python allows mixing 'and' and 'or' without parentheses; they have defined precedence. No syntax error occurs. The expression is valid and evaluates according to precedence rules. This option incorrectly assumes that parentheses are mandatory for mixing logical operators, which is not true in Python.

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 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.