Question Detail

COS 102 If staments Objective Question

Question

What is the consequence of incorrectly indenting the code block following an if statement in Python?
Options
A The program will run but produce incorrect results.
B Python will automatically correct the indentation.
C The program will execute the indented code regardless of the condition.
D It will result in a syntax or indentation error, preventing the program from running correctly.
Correct Answer
Correct Answer

Option D is the correct answer.

Detailed Explanation

Page 15, 'Mistake #2: Colon & Indent', explains: 'Indentation: Python uses whitespace to know what code belongs to the if block.' Incorrect indentation means Python cannot determine the code block, leading to an error.

Hint

Recall the importance of 'whitespace' in Python for defining code blocks.

Question Info