PCEP Control Flow, Loops, Lists and Logic Practice Question
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?
⚠ Common exam trap
Python Institute often tests the misconception that condition order is irrelevant in if-elif-else chains, tempting candidates to pick Option A, when in fact the sequential evaluation makes order crucial.
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
✓
The condition for 'A' should be checked before 'B'
In an if-elif-else chain, the first matching condition is executed and the rest are skipped. If the condition for 'A' (e.g., score >= 90) is placed after the condition for 'B' (e.g., score >= 80), a score of 90 will match the 'B' condition first and never reach the 'A' condition. To fix this, the most restrictive condition (highest grade) must be checked first.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The order of conditions does not matter
Why it's wrong here
Condition order in an if-elif chain determines which branch executes first, so it directly causes a score of 90 to match a lower band. It is tempting because each condition is individually correct, and would be correct if the branches were mutually exclusive and could not overlap.
- ✗
The elif condition should use >= instead of >
Why it's wrong here
Using >= would make the 90 boundary inclusive, but the bug stems from overlapping or misordered conditions earlier in the chain, so the first matching branch captures 90 before the intended one. It is tempting because boundary comparisons are a common source of off-by-one errors in score classifiers.
- ✓
The condition for 'A' should be checked before 'B'
Why this is correct
Python evaluates conditions top-down and stops at the first true branch. If the 'B' condition (for example score >= 80) precedes the 'A' condition, a score of 90 matches 'B' first, so ordering the 'A' check earlier fixes it.
- ✗
The code uses elif instead of else if
Why it's wrong here
Python has no 'else if' keyword; elif is correct syntax, so this cannot explain the misclassification. It is tempting because elif resembles other languages' else-if construct, and would be correct if the code genuinely used invalid conditional syntax causing a runtime error.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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. 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?
easy- A.for score in scores: if score == 100: pass ...
- ✓ B.for score in scores: if score == 100: break ... further processing
- C.for i in range(len(scores)): if scores[i] == 100: exit() ...
- D.while scores: score = scores.pop(); if score == 100: continue ...
Why B: The `break` statement immediately exits the loop when a score of 100 is encountered, which matches the requirement to stop processing further scores. The `for` loop iterates over the list naturally, and the `if` condition checks for the perfect score, making this the most straightforward and efficient construct for this scenario.
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.