PCEP Control Flow, Loops, Lists and Logic Practice Question
A data analyst has a list of temperature readings in Celsius and wants to create a new list containing only readings that are valid (>= -273.15 and <= 1000). Which code correctly creates the filtered list?
⚠ Common exam trap
Python Institute often tests the distinction between inclusive (`<=`, `>=`) and exclusive (`<`, `>`) comparisons, and the trap here is that candidates may overlook the boundary values or choose a syntactically incorrect loop structure like Option C.
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
✓
valid = [temp for temp in temps if -273.15 <= temp <= 1000]
It uses a list comprehension with a chained comparison (`-273.15 <= temp <= 1000`) that correctly includes both boundary values. This syntax is Pythonic and ensures temperatures equal to -273.15 or 1000 are considered valid, matching the requirement exactly.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
valid = [temp for temp in temps if -273.15 <= temp <= 1000]
Why this is correct
Correct; uses chained comparison to include boundaries.
- ✗
valid = [temp for temp in temps if temp > -273.15 and temp < 1000]
Why it's wrong here
Excludes -273.15 and 1000.
- ✗
valid = [] for t in temps: if t > -273.15 and t < 1000: valid.append(t)
Why it's wrong here
Invalid syntax; missing colon or indentation.
- ✗
valid = list(filter(lambda t: t >= -273.15, temps))
Why it's wrong here
Only checks lower bound.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-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.