Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A data analyst has a list `readings` of numeric sensor values and needs to build a new list `scaled` that contains each reading multiplied by 2, but only for readings that are positive. Negative and zero readings should be excluded. Which code correctly produces `scaled`?

⚠ Common exam trap

The trap here is mixing up the filter condition with the transformation, or using >= instead of >, which would incorrectly include zero readings.

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

✓

scaled = [r * 2 for r in readings if r > 0]

The correct comprehension uses a filter clause after the for to include only positive readings, then multiplies each by 2 in the expression. This produces a new list containing doubled values for positive readings only, excluding negatives and zeros. It matches the analyst's specification and uses idiomatic Python syntax.

Answer analysis

Option-by-option breakdown

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

  • ✗

    scaled = [r * 2 for r in readings if r >= 0]

    Why it's wrong here

    The condition r >= 0 includes zero readings, which the scenario says should be excluded. While it correctly filters out negatives, it fails to remove zeros. The resulting list would contain an extra 0 for each zero reading, violating the requirement to include only positive values.

  • ✓

    scaled = [r * 2 for r in readings if r > 0]

    Why this is correct

    This list comprehension applies the filter r > 0 before including an element and then multiplies each qualifying reading by 2. Negative and zero values are excluded by the condition, and only positive readings appear in the new list. It is concise, correct, and uses standard Python list comprehension syntax with a filter clause.

  • ✗

    scaled = [r * 2 if r > 0 for r in readings]

    Why it's wrong here

    The syntax is invalid because a conditional expression in a list comprehension must include an else clause when used before the for, such as r * 2 if r > 0 else None. As written, Python raises a SyntaxError. Even if corrected with else, it would include entries for non-positive readings, which is not desired.

  • ✗

    scaled = [r for r in readings if r > 0] * 2

    Why it's wrong here

    This first builds a list of positive readings without scaling, then multiplies the entire list by 2, which repeats the list elements rather than doubling each number. For example, [1,2] * 2 becomes [1,2,1,2]. This does not compute the scaled values and produces duplicates, so it is incorrect for the scenario.

About these practice questions

This PCEP question is part of Courseiva's 482-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 →

How Courseiva writes practice questions · Editorial policy

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.