Foundations-of-Programming-Python practice question 4 of 10
What must be consistent within a Python code block for the code to run without syntax errors?
Full set: 60 questionsPython uses indentation to define the structure and grouping of statements into code blocks. Unlike other languages that use braces or keywords, Python requires that all statements within a single block must be indented at the same level. An IndentationError, a subtype of SyntaxError, is raised if the indentation is inconsistent, preventing the code from running. This strict requirement ensures code readability and unambiguous structure.
A. Inconsistent variable names cause logical or NameError issues at runtime, not syntax errors related to the code block's structure.
C. Comment placement is flexible and does not affect the execution flow or the definition of a code block.
D. Line length is a style guideline (PEP 8) for readability; exceeding recommended lengths does not cause a syntax error.
1. Python Software Foundation. (2023). The Python Language Reference (Version 3.12.0). Section 2.1.8: Indentation. Retrieved from https://docs.python.org/3/reference/lexicalanalysis.html#indentation
2. Python Software Foundation. (2023). The Python Tutorial (Version 3.12.0). Section 4.1: if Statements. Retrieved from https://docs.python.org/3/tutorial/controlflow.html#if-statements
3. Guttag, J. V. (2016). Introduction to Computation and Programming Using Python, With Application to Understanding Data (2nd ed.). MIT Press. Chapter 2.2: Branching Programs. (Discusses the role of indentation in structuring conditional blocks).
Keep practicing
Take the free Foundations-of-Programming-Python practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Foundations-of-Programming-Python practice questions
- Question 1Which components are required in every Python for loop?
- Question 2Which keyword moves a loop immediately to its subsequent iteration?
- Question 3A program needs to update all values in a list by adding 5 to each number. Which for loop…
- Question 5Which Python data structure cannot be modified after creation?
