Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A validation script defines a list named flags containing boolean values. The script must determine whether every flag is True and print 'All clear' only in that case; otherwise it should print 'Check needed'. Which code fragment implements this logic correctly?

⚠ Common exam trap

Candidates often confuse any with all or assuming that a non-empty list of booleans is itself a reliable truth test for all values being True.

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

✓

if all(flags): print('All clear') else: print('Check needed')

Determining that every element is True requires a check that inspects all elements and fails if any is falsy. The built-in all function does exactly that, returning True only when every element is truthy and False otherwise, which maps directly onto the two required messages.

Answer analysis

Option-by-option breakdown

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

  • ✗

    if flags: print('All clear') else: print('Check needed')

    Why it's wrong here

    Using the list itself as a condition tests only whether the list is non-empty. A list containing False values is still non-empty and therefore truthy, so the script would incorrectly print 'All clear' even when some flags are False.

  • ✗

    if any(flags): print('All clear') else: print('Check needed')

    Why it's wrong here

    The any function returns True when at least one element is truthy, not when all are. A list containing a single True and several False values would incorrectly print 'All clear', so this fragment does not enforce the requirement that every flag be True.

  • ✓

    if all(flags): print('All clear') else: print('Check needed')

    Why this is correct

    The built-in all function returns True when every element in the iterable is truthy. For a list of booleans, that means all values must be True, so the conditional prints the correct message for both the all-True and any-False cases.

  • ✗

    if flags == True: print('All clear') else: print('Check needed')

    Why it's wrong here

    Comparing a list to the boolean True with == is always False because a list and a boolean are different types. The condition never succeeds, so the script always prints 'Check needed' regardless of the contents of flags.

About these practice questions

One of 482 original PCEP 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 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.