PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
Network Topology
Refer to the exhibit. What is the output?
⚠ Common exam trap
The PCEP exam often tests the distinction between iterating over all elements of a tuple versus accessing a single element by index, leading candidates to mistakenly think the final print repeats the entire loop or that the loop stops early.
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
✓
1 2 3 --- 1
The code defines a tuple t = (1, 2, 3) and iterates over it with a single for loop, printing each element on a separate line. After the loop, it prints a separator line of dashes (---) and then prints the first element t[0] which is 1. The output is therefore 1, 2, 3, ---, 1 — exactly matching option B.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
1 2 --- 1
Why it's wrong here
Incorrect. The first loop prints 1,2,3 not just 1,2.
- ✓
1 2 3 --- 1
Why this is correct
Correct. First loop prints all three, second loop prints only first then breaks.
- ✗
1 2 3 --- 1 2 3
Why it's wrong here
Incorrect. The break stops the loop after first iteration.
- ✗
1 --- 1
Why it's wrong here
Incorrect. The first loop prints all three.
Go deeper
Related to this question
About these practice questions
One of 498 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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Refer to the exhibit. What is the output when the code is executed?
hard- A.0 1 2
- B.0 0 0
- ✓ C.2 2 2
- D.3 3 3
Why C: The code defines a tuple `t = (0, 1, 2)`. The `for` loop iterates over the tuple, but each iteration prints `t[2]`, which is the third element (index 2) with value 2. Since the value is constant, it prints '2' three times. Hence the output is '2 2 2'.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.