PCEP Computer Programming and Python Fundamentals Practice Question
While debugging a Python script, you see the following error: 'IndentationError: expected an indented block'. The code appears to be correctly indented with spaces. What is the most likely cause?
⚠ Common exam trap
The PCEP exam often tests the misconception that any indentation inconsistency (like wrong number of spaces) causes an IndentationError, when in fact Python only cares about consistency and does not enforce a specific number of spaces.
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
✓
You mixed tabs and spaces for indentation.
Mixing tabs and spaces for indentation is a common cause of 'IndentationError: expected an indented block' even when the code appears correctly indented. Python 3 disallows mixing tabs and spaces; it uses the exact whitespace characters to determine block structure, and inconsistent usage triggers this error.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
You used the wrong number of spaces (e.g., 2 spaces instead of 4).
Why it's wrong here
Python does not require a specific number, only consistency within a block.
- ✗
You forgot to include a colon at the end of a compound statement.
Why it's wrong here
Colon omission leads to SyntaxError, not IndentationError.
- ✗
The script has a logic error in the condition.
Why it's wrong here
Logic errors do not cause IndentationError.
- ✓
You mixed tabs and spaces for indentation.
Why this is correct
Mixture of tabs and spaces is a common cause of IndentationError.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
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 programmer writes the following code: if x > 5: print('Greater') What is the most likely cause of an IndentationError?
medium- ✓ A.The print statement is not indented.
- B.The comparison operator is wrong.
- C.The variable x is undefined.
- D.The colon after the condition is missing.
Why A: In Python, the colon at the end of an if statement signals the start of an indented block. The print statement must be indented (typically 4 spaces) to be part of that block. Without indentation, Python raises an IndentationError because it expects a suite of statements under the if clause.
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.