Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

In a Python if-elif-else construct, if the first condition is evaluated as true, what happens next?
Options
A All other conditions (<code>elif</code>) are still evaluated.
B Only the <code>else</code> block is executed.
C The body of the first true condition is executed, and no other conditions or bodies are evaluated.
Correct Answer
D The program terminates with an error.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 44 explains: 'If the first condition succeeds, the first body will be executed; no other conditions or bodies are evaluated in that case.' This is a key aspect of how if-elif-else chains work.

Hint

Consider the 'exclusive' nature of an if-elif-else chain once a true condition is found.

Question Info