Python Programming - Conditional Statements - Discussion

Discussion Forum : Conditional Statements - General Questions (Q.No. 4)
4.
Which of the following is the correct syntax for an if statement with multiple conditions?
if condition1:
    # code block
if condition2:
    # code block
if condition1:
    # code block
elif condition2:
    # code block
if condition1:
    # code block
else if condition2:
    # code block
if condition1:
    # code block
else condition2:
    # code block
Answer: Option
Explanation:

The correct syntax for an if statement with multiple conditions is to use elif (short for "else if") for subsequent conditions after the initial if statement.

Option A is also a valid syntax for handling multiple conditions, but it doesn't ensure mutual exclusivity between the conditions. In this case, both code blocks would execute if both condition1 and condition2 are true.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.