PCEP · topic practice

Control Flow, Loops, Lists and Logic practice questions

Practise Certified Entry-Level Python Programmer PCEP Control Flow, Loops, Lists and Logic practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Reviewed byJohnson Ajibi· MSc IT Security
20 questionsDomain: Control Flow, Loops, Lists and Logic

What the exam tests

What to know about Control Flow, Loops, Lists and Logic

Control Flow, Loops, Lists and Logic questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Control Flow, Loops, Lists and Logic exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Practice set

Control Flow, Loops, Lists and Logic questions

20 questions · select your answer, then reveal the explanation

A developer writes a loop to sum numbers from 1 to 10. The code outputs 55, but the expected sum is 55. However, the loop uses a range that includes 0. Which range should be used to achieve the correct sum?

A programmer needs to iterate over a list of strings and print each string in uppercase. Which loop correctly accomplishes this?

A programmer writes code that uses a while loop to process user input until the user types 'exit'. The code currently prints 'Done' after the loop, but it never exits. What is the most likely cause?

A list of numbers is defined as nums = [1, 2, 3, 4, 5]. Which expression returns the last element?

A list contains strings and numbers: items = ['apple', 10, 'banana', 20]. A programmer wants to create a new list that contains only the strings. Which approach is correct?

A developer writes the following code snippet:

for i in range(3):
    for j in range(2):
        if i == j:

break else:

print(i, 'outer')

What is the output?

A programmer needs to check if at least one element in a list of booleans flags is True. Which expression correctly does this?

Given the code: x = [1, 2, 3] y = x y.append(4)

print(x)

What is the output?

A programmer wants to create a list of even numbers from 0 to 10 inclusive. Which list comprehension is correct?

What is the output of the code?

Exhibit

Refer to the exhibit.

for i in range(5):
    if i == 3:
        continue
    print(i, end=' ')

A developer runs main.py and gets True. They then modify config.py by adding `allowed_ports.append(22)` and run main.py again without restarting the interpreter. What is the output?

Exhibit

Refer to the exhibit.

# config.py
allowed_ports = [80, 443, 8080]

def check_port(port):
    if port in allowed_ports:
        return True
    else:
        return False

# main.py
from config import check_port
print(check_port(80))

Which TWO of the following are valid ways to create a list with elements 10, 20, 30?

Which TWO of the following code snippets will print the numbers 0, 1, 2, 3, 4?

Which THREE of the following are valid list operations?

You are working on a network automation script that reads a configuration file containing firewall rules. Each rule is a dictionary with keys 'source_ip', 'dest_ip', 'action'. The script must iterate over the rules and print all rules where action is 'allow'. However, the script is not printing any output even though there are allow rules in the file. The code snippet is:

rules = [{'source_ip':'10.0.0.1','dest_ip':'10.0.0.2','action':'allow'},

{'source_ip':'10.0.0.2','dest_ip':'10.0.0.3','action':'deny'}]
for rule in rules:
    if rule('action') == 'allow':
        print(rule)

What is the most likely cause of the problem?

You are writing a script to parse a log file. Each line in the log contains a timestamp and a message separated by a colon. You need to extract only the messages that contain the word 'ERROR'. The script uses a list comprehension to filter lines. However, the script crashes with a 'ValueError: not enough values to unpack' when processing some lines. The code is:

lines = ['2024-01-01 12:00:00: INFO: all good', '2024-01-01 12:01:00: ERROR: something wrong'] errors = [msg for timestamp, msg in line.split(': ') for line in lines if 'ERROR' in msg]

What is the correct fix?

Arrange the steps to handle an exception in Python using try-except.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

Arrange the steps to install a third-party Python package using pip.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

Match each exception type to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Raised when a function receives an argument of correct type but inappropriate value

Raised when an operation is applied to an object of inappropriate type

Raised when a sequence subscript is out of range

Raised when a mapping key is not found in a dictionary

Raised when division or modulo operation is performed with zero as divisor

Match each Python concept to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

A name that references a value in memory

A block of reusable code that performs a specific task

A file containing Python definitions and statements

A collection of modules organized in directories

A blueprint for creating objects

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Control Flow, Loops, Lists and Logic sessions

Start a Control Flow, Loops, Lists and Logic only practice session

Every question in these sessions is drawn from the Control Flow, Loops, Lists and Logic domain — nothing else.

Related practice questions

Related PCEP topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the PCEP exam test about Control Flow, Loops, Lists and Logic?
Control Flow, Loops, Lists and Logic questions test whether you can apply the concept in context, not just recognise a definition.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Control Flow, Loops, Lists and Logic questions in a focused session?
Yes — the session launcher on this page draws every question from the Control Flow, Loops, Lists and Logic domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other PCEP topics?
Use the topic links above to move to related areas, or go back to the PCEP question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the PCEP exam covers. They are not copied from any real exam or dump site.