PCEP Computer Programming and Python Fundamentals Practice Question
A programmer writes the following code to classify a temperature reading: temp = 25 if temp > 30: print('Hot') elif temp > 20: print('Warm') else: print('Cool') What is printed when this code runs?
⚠ Common exam trap
The trap here is misreading the boundary conditions or assuming the first condition is true without checking the actual value of temp.
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 if-elif-else structure evaluates conditions top-down. Since temp is 25, the first condition (temp > 30) is false, the second (temp > 20) is true, so the 'Warm' branch executes. The else is bypassed. The other outputs would occur only if the temperature fell into different ranges or if the code were invalid.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Cool
Why it's wrong here
The else block runs only if all preceding conditions are false. Here, temp > 20 is true, so the elif block executes and the else is skipped. 'Cool' would be printed only if temp were 20 or less. Since temp is 25, this is not the correct output.
- ✗
Nothing is printed because the code has a syntax error.
Why it's wrong here
The code is syntactically correct: it uses if, elif, and else with proper colons and indentation. There is no syntax error. The conditions are evaluated in order, and the appropriate block prints. Therefore, an output is produced, and it is not nothing.
- ✓
Warm
Why this is correct
The first condition temp > 30 evaluates to False because 25 is not greater than 30. The elif condition temp > 20 evaluates to True because 25 is greater than 20. Therefore, the block under elif executes, printing 'Warm'. The else block is skipped. This is the correct output.
- ✗
Hot
Why it's wrong here
The condition for 'Hot' is temp > 30. Since temp is 25, this condition is false. The elif condition temp > 20 is true, so 'Warm' is printed. 'Hot' would only be printed if the temperature exceeded 30, which is not the case here.
Go deeper
Related to this question
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 →
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.