Courseiva

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

    Using 'or' makes the condition true when either test passes, so a negative even number or a positive odd number would wrongly qualify. It is tempting because both required checks appear, and 'or' would be correct if the task were to accept numbers satisfying at least one criterion.

  • ✓

    if num > 0 and num % 2 == 0:

    Why this is correct

    The `and` operator short-circuits, so `num % 2 == 0` is only evaluated when `num > 0` already holds, satisfying both required conditions in one expression. Using `or` would accept any positive number regardless of parity, while nested `if` statements would work but are not the single expression the stem requests.

  • ✗

    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

    The modulo operator is missing its left operand, so '% 2 == 0' is a syntax error rather than a valid comparison. It is tempting because the 'and' correctly joins both required conditions, and this structure would be right if the remainder were written as 'num % 2 == 0'.

About these practice questions

One of 482 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 →

How Courseiva writes practice questions · Editorial policy

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.