PCEP Computer Programming and Python Fundamentals Practice Question
A developer needs to check if a number is positive and even. Which conditional expression is correct?
⚠ Common exam trap
The PCEP exam often tests the distinction between logical operators (`and`, `or`) and bitwise operators (`&`, `|`), as well as the difference between assignment (`=`) and comparison (`==`), to catch candidates who confuse syntax from other programming languages.
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
✓
if num > 0 and num % 2 == 0:
Python uses the keyword `and` for logical conjunction, and the equality operator is `==` (not `=`). The expression `num > 0 and num % 2 == 0` correctly checks that `num` is both greater than zero and divisible by 2 with no remainder, which defines a positive even number.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
if num > 0 & num % 2 == 0:
Why it's wrong here
& is bitwise AND, different precedence.
- ✗
if num > 0 and num % 2 = 0:
Why it's wrong here
A single equals sign is assignment, not comparison, so the expression is a syntax error inside an if statement. It is tempting because the intent reads correctly to anyone skimming, and the first half of the condition is valid.
- ✗
if num > 0 && num % 2 == 0:
Why it's wrong here
Python uses the keywords and, or and not for logical operators; && is C and Java syntax and raises a SyntaxError here. The valid expression joins the two comparisons with and. The && token would be correct in languages such as C, C++ or Java.
- ✓
if num > 0 and num % 2 == 0:
Why this is correct
Combining `num > 0` with `num % 2 == 0` using `and` requires both conditions to hold simultaneously, correctly identifying positive even numbers. The modulo operator returns zero only for even values, while the comparison excludes zero and negatives, satisfying the stem's dual constraint in one expression.
Go deeper
Related to this question
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 →
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.