Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Regarding the Python `if-elif-else` conditional construct, which statement is true?
Options
A An `if` statement must always be followed by at least one `elif` clause.
B The final `else` clause is mandatory and cannot be omitted.
C There can be any number of `elif` clauses, including zero.
Correct Answer
D If an `elif` condition evaluates to true, subsequent `elif` and `else` clauses will still be evaluated to ensure all possibilities are checked.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 45 of the document states: "There may be any number of elif clauses (including zero), and The final else clause is optional." Also, if a condition is met, no other conditions are evaluated.

Hint

Consider the flexibility of conditional structures. Are all parts strictly necessary, or can some be left out?

Question Info