PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A program needs to check if a number is both positive and even. Which expression correctly implements this?
⚠ Common exam trap
Python Institute often tests the distinction between logical operators (`and`, `or`) and bitwise operators (`&`, `|`), as well as the correct syntax for the modulo operator, to catch candidates who confuse these concepts.
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:
It uses the logical `and` operator to combine two conditions: `num > 0` (checks if the number is positive) and `num % 2 == 0` (checks if the number is even). Both conditions must be true for the overall expression to be true, which correctly implements the requirement of checking if a number is both positive and even.
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 or num % 2 == 0:
Why it's wrong here
True if either condition holds, not both.
- ✓
if num > 0 and num % 2 == 0:
Why this is correct
Correct: both conditions must be true.
- ✗
if num > 0 & num % 2 == 0:
Why it's wrong here
Bitwise & has higher precedence than comparisons, leads to incorrect evaluation.
- ✗
if num > 0 and % 2 == 0:
Why it's wrong here
Syntax error: missing operand for %.
Go deeper
Related to this question
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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A developer needs to check if a number is positive and even. Which conditional expression is correct?
medium- A.if num > 0 & num % 2 == 0:
- B.if num > 0 and num % 2 = 0:
- C.if num > 0 && num % 2 == 0:
- ✓ D.if num > 0 and num % 2 == 0:
Why D: 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.
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.