PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A login script checks whether a username entered by the user is exactly 'admin' and the account is not locked. The variable locked is a boolean. Which expression evaluates to True only when the username is 'admin' and locked is False?
⚠ Common exam trap
The trap here is choosing or because it reads naturally in English, when the requirement demands that both conditions be true simultaneously.
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
✓
username == 'admin' and not locked
The rule requires two conditions to hold together: the username must equal 'admin' and the account must not be locked. The and operator enforces both, while not locked converts the boolean to its opposite. Using or would allow access when only one condition is satisfied, and testing locked directly reverses the security check.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
username == 'admin' and not locked
Why this is correct
The equality test confirms the exact username, and not locked is True only when locked is False. The and operator requires both sides to be truthy, so the whole expression is True exactly when the username matches and the account is unlocked. This correctly encodes both conditions.
- ✗
not username == 'admin' and not locked
Why it's wrong here
The leading not negates the username comparison, so the expression is True when the username is not 'admin' and the account is unlocked. That is the inverse of the login rule. Operator precedence applies not to the comparison first, but the overall meaning still rejects the intended admin user.
- ✗
username == 'admin' and locked
Why it's wrong here
This requires locked to be True, which is the opposite of the intended condition. It would grant access only when the account is locked, exactly backwards from the security requirement. The and operator correctly combines conditions, but the second operand tests the wrong boolean state.
- ✗
username == 'admin' or not locked
Why it's wrong here
With or, the expression is True if either condition holds. A locked account with the correct username would still pass because the username test is True. This grants access too broadly, defeating the purpose of checking the lock state. The scenario demands both conditions simultaneously.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
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.