Courseiva
Software Development and DesignhardMultiple ChoiceObjective-mapped

200-901 Software Development and Design Practice Question

A Python script uses a list comprehension: [x**2 for x in range(20) if x % 2 == 0]. Which of the following is equivalent?

⚠ Common exam trap

Cisco often tests the distinction between list comprehensions with and without a filtering condition, and the trap here is that candidates may overlook the `if x % 2 == 0` filter and choose Option C, which omits the condition entirely.

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

result = [] for x in range(20): if x % 2 == 0: result.append(x**2)

It directly translates the list comprehension into an equivalent for-loop with a conditional append. The comprehension `[x**2 for x in range(20) if x % 2 == 0]` iterates over numbers 0–19, filters for even numbers (x % 2 == 0), squares each, and collects the results in a list. Option A's explicit loop and conditional produce the exact same sequence of appended values.

Answer analysis

Option-by-option breakdown

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

  • result = [] for x in range(20): if x % 2 == 0: result.append(x**2)

    Why this is correct

    This loop explicitly does the same filtering and squaring.

  • result = map(lambda x: x**2, filter(lambda x: x % 2 == 0, range(20)))

    Why it's wrong here

    While functional, it returns a map object, not a list; but list(map(...)) would be equivalent. However, the question asks for equivalent code, and this answer is not a complete list conversion. The loop is the most direct equivalent.

  • result = [] for x in range(20): result.append(x**2)

    Why it's wrong here

    This appends squares of all numbers, not just even ones.

  • result = [x**2 for x in range(20) if x % 2 != 0]

    Why it's wrong here

    This selects odd numbers, the opposite condition.

About these practice questions

One of 989 original 200-901 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

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 200-901 practice question is part of Courseiva's free Cisco 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 200-901 exam.