Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

An application requires different messages based on temperature. Given: temp = 25

if temp > 30:
    print('Hot')

elif temp > 20:

print('Warm')

else:

print('Cool')

What is the output?

⚠ Common exam trap

The PCEP exam often tests the misconception that `elif` is optional or that the `else` block will execute even when a preceding `elif` is True, leading candidates to incorrectly choose 'Cool'.

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

✓

Warm

The condition `temp > 30` is False (25 is not greater than 30), so the first `if` block is skipped. The `elif temp > 20` condition is True (25 > 20), so the `print('Warm')` statement executes, outputting 'Warm'. Option D is correct.

Answer analysis

Option-by-option breakdown

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

  • ✗

    No output

    Why it's wrong here

    Every if/elif/else chain executes exactly one branch, so output always occurs. Selecting 'No output' assumes a syntax or runtime failure that does not exist; the code is valid and temp=25 satisfies the elif, printing 'Warm'.

  • ✗

    Hot

    Why it's wrong here

    With temp = 25, the first condition (temp > 30) evaluates to False, so its block is skipped; the elif condition (temp > 20) is True, printing 'Warm'. Choosing 'Hot' ignores that Python tests conditions sequentially and stops at the first match. 'Hot' would print only if temp exceeded 30.

  • ✗

    Cool

    Why it's wrong here

    The elif condition temp > 20 evaluates true for 25, so 'Warm' prints and the else branch is skipped entirely. Choosing 'Cool' ignores that elif short-circuits before else; else only runs when all preceding conditions are false, which is not the case here.

  • ✓

    Warm

    Why this is correct

    The first condition, temp > 30, evaluates false because 25 is not greater than 30. The elif condition, temp > 20, evaluates true, so its block runs and prints Warm; the else branch is skipped.

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