Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Control Flow, Loops, Lists and Logic practice sets

PCEP Control Flow, Loops, Lists and Logic • Complete Question Bank

PCEP Control Flow, Loops, Lists and Logic — All Questions With Answers

Complete PCEP Control Flow, Loops, Lists and Logic question bank — all 0 questions with answers and detailed explanations.

88
Questions
Free
No signup
Certifications/PCEP/Practice Test/Control Flow, Loops, Lists and Logic/All Questions
Question 1easymultiple choice
Read the full Control Flow, Loops, Lists and Logic 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?

Question 2easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 3mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 4easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 5mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 6hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 7mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 8hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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

print(x)

What is the output?

Question 9easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 10mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.

for i in range(5):
    if i == 3:
        continue
    print(i, end=' ')
Question 11hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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))
Question 12mediummulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 13hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 14easymulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which THREE of the following are valid list operations?

Question 15hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 16mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 17mediumdrag order
Study the full Python automation breakdown →

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
Question 18mediumdrag order
Study the full Python automation breakdown →

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
Question 19mediummatching
Read the full Control Flow, Loops, Lists and Logic explanation →

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

Question 20mediummatching
Study the full Python automation breakdown →

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

Question 21easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A junior developer needs to write code that processes a list of student scores and stops processing when a score of 100 is encountered, as that score represents a perfect score that should be treated separately. Which loop construct is most appropriate?

Question 22mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

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?

Question 23hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer is implementing a toggle switch feature. The variable flag starts as False. Which code snippet correctly toggles the flag and performs an action based on the new value each time the code is run? (Assume action1 is performed when flag is True, action2 when False.)

Question 24easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Which code correctly and efficiently sums only positive numbers from a list?

Question 25mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer needs to iterate over a list of network interfaces and print only the names that start with 'eth'. Which code should be used?

Question 26hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A programmer has a list of tuples representing (product, price) and wants to find the highest price. Which code correctly finds the maximum price?

Question 27easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Which code correctly creates a list of squares for numbers 1 to 5 using a list comprehension?

Question 28mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer needs to implement a loop that prints numbers from 10 down to 1. Which loop correctly achieves this?

Question 29hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A program contains a nested while loop. The inner loop should run as long as a condition is True, but the outer loop should stop after 3 iterations. Which code structure is correct? (Assume the inner loop condition is inner < 5.)

Question 30easymulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which two of the following list methods modify the original list in place? (Choose two.)

Question 31mediummulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which two of the following expressions evaluate to True? (Choose two.)

Question 32hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which three of the following statements about lists are true? (Choose three.)

Question 33mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the output?

Exhibit

numbers = [5, 2, 8, 1, 9]
for i in range(len(numbers)):
    for j in range(0, len(numbers)-i-1):
        if numbers[j] > numbers[j+1]:
            numbers[j], numbers[j+1] = numbers[j+1], numbers[j]
print(numbers[0])
Question 34hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is printed?

Exhibit

data = [1, 2, 3, 4, 5]
result = []
for x in data:
    if x % 2 == 0:
        result.append(x * 2)
    else:
        result.append(x * 3)
print(result[2])
Question 35easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the output?

Exhibit

count = 0
while count < 5:
    count += 1
    if count == 3:
        continue
    print(count, end=' ')
Question 36easymultiple choice
Study the full Python automation breakdown →

A company maintains a list of employee names. They want to check if 'Alice' is in the list. Which of the following is the most Pythonic way to achieve this?

Question 37easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer writes a while loop to count down from 10 to 1 and then stop. Which condition should be used?

Question 38easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A team is reviewing code that uses if-elif-else to classify a test score. They notice that for score 90, it prints 'B' instead of 'A'. Which of the following best explains the issue?

Question 39mediummultiple choice
Read the full NAT/PAT explanation →

A developer needs to write a loop that prints all even numbers from a list. They attempt: for num in numbers: if num % 2 == 0: print(num). However, they want a more efficient approach using list comprehension. Which alternative achieves the same result?

Question 40mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A company uses a for loop to iterate over a list of transaction amounts. They want to skip negative amounts. Which statement inside the loop correctly achieves this?

Question 41mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer writes: result = [x**2 for x in range(10) if x % 2 == 0]. What does this code produce?

Question 42hardmultiple choice
Read the full NAT/PAT explanation →

A developer is troubleshooting a loop that terminates earlier than expected. The code is: i = 0; while i < 5: if i == 3: break; print(i); i += 1. What is the output?

Question 43hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A team observes that the following code prints 'Found' even when the item is not in the list. Code: for item in mylist: if item == target: print('Found'); break; else: print('Not found'). Which modification ensures it correctly prints 'Not found' only if the item is not present?

Question 44hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer writes a recursive function to compute factorial, but it causes a RecursionError. Which of the following is the most likely cause?

Question 45easymulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which TWO of the following are valid ways to iterate over a list in reverse order? (Choose two.)

Question 46mediummulti select
Study the full Python automation breakdown →

Which THREE statements about the break statement in Python are correct? (Choose three.)

Question 47hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which TWO of the following code snippets will produce the output '0 1 2'? (Choose two.)

Question 48easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.
nums = [1, 2, 3, 4, 5]
for n in nums:
    if n == 3:
        break
    print(n)
else:
    print('Done')
Question 49mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.
def check(num):
    if num > 0:
        return 'Positive'
    elif num == 0:
        return 'Zero'
    else:
        return 'Negative'

numbers = [10, 0, -5]
results = []
for n in numbers:
    results.append(check(n))
print(results)
Question 50hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.
data = [{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]
for person in data:
    if person['age'] >= 26:
        print(person['name'])
    elif person['age'] < 20:
        print('Too young')
    else:
        print('Check')
Question 51easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the output?

Exhibit

numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
    if numbers[i] % 2 == 0:
        numbers[i] = numbers[i] * 2
print(numbers)
Question 52easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is printed?

Exhibit

x = 10
y = 5
if x > 5 and y < 10:
    result = 'A'
elif x == 10 or y == 5:
    result = 'B'
else:
    result = 'C'
print(result)
Question 53easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the output?

Exhibit

mylist = [0, 1, 2, 3]
print(mylist[1:3])
Question 54easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

How many times will the following loop print 'Hi'?

for i in range(3):
    print('Hi')
Question 55easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Which loop is more efficient for iterating over a large list when you only need the values, not indices?

Question 56mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A company stores employee data as a list of dictionaries. Each dictionary has keys 'name' and 'age'. Which code correctly counts employees older than 30?

Question 57mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A program reverses a string using a while loop. The code is:

text = "hello" reversed_text = "" index = len(text) - 1

while index > 0:

reversed_text += text[index] index -= 1

print(reversed_text)

It prints 'olle' instead of 'olleh'. What is the error?

Question 58mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A student grades system:

score = 85

if score >= 90:

grade = 'A' elif score >= 80: grade = 'B' elif score >= 70: grade = 'C' else: grade = 'F'

What grade is assigned?

Question 59mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Which list method modifies the list in place by adding all elements of another iterable to the end?

Question 60mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A program uses a while loop to find the largest number in a list until a negative number is encountered. What is wrong with this code?

numbers = [3, 7, 2, -1, 5] max_num = 0 i = 0

while numbers[i] >= 0:
    if numbers[i] > max_num:

max_num = numbers[i] i += 1

print(max_num)
Question 61hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer wants to generate a list of squares of integers from 1 to 10 inclusive. Which list comprehension is correct?

Question 62hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer needs to check if all elements in a list of integers are even. Which code correctly implements this?

Question 63hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which TWO of the following list operations modify the list in place?

Question 64hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which THREE of the following are valid ways to iterate over a list?

Question 65hardmulti select
Study the full Python automation breakdown →

Which TWO of the following are true about Python's if statement?

Question 66mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A company needs to filter a list of temperatures in Celsius to only those above 0, then convert to Fahrenheit (multiply by 9/5 and add 32). Which code snippet correctly accomplishes this using a list comprehension?

Question 67easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer writes code to iterate over a list and break when a certain condition is met. Which keyword is used to exit the loop prematurely?

Question 68hardmultiple choice
Read the full NAT/PAT explanation →

A log file processing script uses a while loop to read lines until a specific pattern is found. The code currently hangs. The developer suspects an infinite loop. Which change is most likely to fix the issue?

Question 69mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A program needs to print the index and value of each item in a list named 'items'. Which code snippet correctly does this?

Question 70easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What is the output of the code?

numbers = [1, 2, 3, 4] result = [x**2 for x in numbers if x % 2 == 0]

print(result)
Question 71hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A network engineer writes a script to validate IP addresses. The script checks each octet and prints 'Valid' if all octets are between 0 and 255, otherwise 'Invalid'. However, the script always prints 'Invalid' for valid IPs. The code uses a for loop with an else clause. Which logical error is likely?

Question 72mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Which of the following best describes the behavior of the 'range' function in a for loop?

Question 73easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

What does the following code print?

x = 10

if x > 5:
    if x > 15:
        print("A")

else:

print("B")

else:

print("C")
Question 74mediummulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer is writing a function that takes a list of numbers and returns the sum of all even numbers. Which two code snippets correctly implement this function? (Select two.)

Question 75easymulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

Which two of the following are valid ways to create a list with elements 1, 2, 3? (Select two.)

Question 76hardmulti select
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer is debugging a function that uses a while loop to reverse a list in place. The current code causes an infinite loop. Which three modifications would likely fix the infinite loop? (Select three.)

Question 77mediummultiple choice
Study the full Python automation breakdown →

A system administrator is writing a Python script to monitor server uptime. The script reads a log file line by line, parses timestamps, and stores them in a list. It then loops through the list to detect gaps longer than 5 minutes that indicate a crash. However, the script keeps missing crashes. The current loop is a for loop that iterates over the list using indices. The administrator suspects the loop logic. The loop uses 'for i in range(len(timestamps)-1): if timestamps[i+1] - timestamps[i] > 300: print("Crash detected")'. Timestamps are integers representing seconds since epoch. What is the most likely cause of missed crashes and the best fix?

Question 78hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A data analyst is processing a large dataset of customer transactions. The dataset is stored as a list of dictionaries, each with keys 'amount' and 'date'. The analyst needs to compute the total revenue for 2024. They write:

total = 0

for t in transactions:
    if t['date'].year == 2024:

total += t['amount']

They then run it and get a KeyError: 'date'. After inspection, they notice that some records have a 'Date' key (capital D) instead. The analyst wants to fix this without modifying the data. Which approach will correctly sum amounts regardless of key case?

Question 79easymultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

A developer is writing a simple number guessing game. The computer picks a random number between 1 and 100, and the user keeps guessing until correct. The developer implements:

secret = random.randint(1,100) guess = 0

while guess != secret:

guess = int(input("Guess: "))

if guess == secret:
        print("Correct!")

else:

print("Wrong, try again.")

The game works, but the developer notices that if the user enters something that is not an integer, the program crashes. Which modification ensures the program handles non-integer input gracefully?

Question 80hardmultiple choice
Study the full Python automation breakdown →

A network administrator uses a Python script to analyze firewall logs. The script reads a CSV file with columns 'src_ip', 'dst_ip', 'action', 'time'. It needs to build a list of source IPs that have been blocked more than 3 times. The current code:

blocked_count = {} blocked_ips = []

for row in logs:
    if row['action'] == 'block':
        if row['src_ip'] in blocked_count:

blocked_count[row['src_ip']] += 1 else: blocked_count[row['src_ip']] = 1

for ip, count in blocked_count.items():
    if count > 3:

blocked_ips.append(ip)

The script runs correctly but slowly on large logs. The administrator wants to optimize it. Which change would most improve performance?

Question 81mediummulti select
Study the full Python automation breakdown →

Which two of the following statements about Python lists are true?

Question 82easymultiple choice
Study the full Python automation breakdown →

A junior developer writes a Python script to sum all numbers greater than 10 from a list. The code is:

numbers = [5, 12, 8, 15, 3] total = 0

for num in numbers:
    if num > 10:

total = total + 1

print(total)

The output is 2, but the expected sum is 27 (12+15). Which change will produce the correct output?

Question 83hardmultiple choice
Study the full Python automation breakdown →

A data analyst writes a Python script to double each element in a matrix without altering the original. The code is:

original = [[1,2,3],[4,5,6]] copy = original

for i in range(len(original)):
    for j in range(len(original[i])):

copy[i][j] *= 2

print(original)

The output shows [[2,4,6],[8,10,12]], meaning the original was also changed. Which single modification to the line 'copy = original' ensures the original matrix remains unchanged?

Question 84hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the final value of x after executing the code?

Exhibit

Python 3.11.0 (default, Oct 24 2022, 14:48:10)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1, 2, 3]
>>> for i in range(len(x)):
...     x.insert(i, x.pop())
...
>>> x
[1, 2, 3]
Question 85hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. Why does the code successfully remove all even numbers but the output is [1, 3, 5]?

Exhibit

>>> nums = [0, 1, 2, 3, 4, 5]
>>> for i in range(len(nums)):
...     if nums[i] % 2 == 0:
...         nums.remove(nums[i])
...
>>> nums
[1, 3, 5]
Question 86hardmultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What does the else clause of the inner for loop do?

Exhibit

>>> data = [[1,2], [3,4], [5,6]]
>>> result = []
>>> for row in data:
...     for item in row:
...         if item % 2 == 0:
...             break
...     else:
...         result.append(row)
>>> result
[[1,2], [5,6]]
Question 87mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the output of the code?

Exhibit

>>> x = 0
>>> while x < 5:
...     x += 1
...     if x == 3:
...         continue
...     print(x, end=' ')
1 2 4 5
Question 88mediummultiple choice
Read the full Control Flow, Loops, Lists and Logic explanation →

Refer to the exhibit. What is the final value of my_list?

Exhibit

>>> my_list = [1, 2, 3, 4, 5]
>>> for i in range(len(my_list)):
...     if my_list[i] % 2 == 0:
...         my_list[i] = my_list[i] ** 2
...     else:
...         my_list[i] = my_list[i] ** 3
>>> my_list
[1, 4, 27, 16, 125]

Practice tests

Scored 10-question sessions with instant feedback and explanations.

PCEP Practice Test 1 — 10 Questions→PCEP Practice Test 2 — 10 Questions→PCEP Practice Test 3 — 10 Questions→PCEP Practice Test 4 — 10 Questions→PCEP Practice Test 5 — 10 Questions→PCEP Practice Exam 1 — 20 Questions→PCEP Practice Exam 2 — 20 Questions→PCEP Practice Exam 3 — 20 Questions→PCEP Practice Exam 4 — 20 Questions→Free PCEP Practice Test 1 — 30 Questions→Free PCEP Practice Test 2 — 30 Questions→Free PCEP Practice Test 3 — 30 Questions→PCEP Practice Questions 1 — 50 Questions→PCEP Practice Questions 2 — 50 Questions→PCEP Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

Computer Programming and Python FundamentalsData Types, Variables, Basic I/O and OperatorsControl Flow, Loops, Lists and LogicFunctions, Tuples, Dictionaries and Exceptions

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Control Flow, Loops, Lists and Logic setsAll Control Flow, Loops, Lists and Logic questionsPCEP Practice Hub