Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A student writes a program to classify a number:

num = 7 result = num > 5 and num < 10 or num == 0

print(result)

What is printed, and why?

⚠ Common exam trap

The trap here is misremembering operator precedence and assuming or is evaluated before and, which would flip the grouping and change the result.

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, because and has higher precedence than or, so (num > 5 and num < 10) is evaluated first and is True.

Python's logical operators follow a precedence order with and binding tighter than or, and comparison operators binding tighter than both. The expression is grouped as (num > 5 and num < 10) or (num == 0). With num = 7, the first group is True, so the entire expression short-circuits to True, and that value is printed.

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, because comparison operators are evaluated after logical operators.

    Why it's wrong here

    Comparison operators such as >, <, and == have higher precedence than logical operators and or or, so they are evaluated first, not after. The explanation in this option states the opposite of Python's actual precedence rules, even though the printed value happens to be True for this input.

  • ✗

    False, because or is evaluated before and, making the expression False.

    Why it's wrong here

    This option reverses the actual precedence: and binds more tightly than or. If or were evaluated first, the grouping would change, but that is not how Python parses the expression. With num = 7, the correct grouping yields True, so this result is incorrect.

  • ✓

    True, because and has higher precedence than or, so (num > 5 and num < 10) is evaluated first and is True.

    Why this is correct

    Python gives and higher precedence than or, so the expression groups as (num > 5 and num < 10) or (num == 0). For num = 7, both comparisons in the first group are true, making the group True. Since True or anything is True, the whole expression evaluates to True. The precedence rule is the key to understanding the result.

  • ✗

    False, because num == 0 is False and that makes the whole expression False.

    Why it's wrong here

    In an or expression, if either side is True the result is True. The left side (num > 5 and num < 10) is True for 7, so the whole expression is True regardless of the right side being False. This option treats or as if it required both sides to be true.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.