Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

The else clause in a Python if-elif-else construct is:
Options
A Always mandatory.
B Optional.
Correct Answer
C Only mandatory if there are <code>elif</code> clauses.
D Only used for error handling.
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 45 explicitly states: 'The final else clause is optional.' This means you can have if statements, or if-elif chains, without an else block.

Hint

Think about whether every conditional statement *must* have a fallback action.

Question Info