Which of the following is True with respect to conditional statements in Python? (1 Point)
-Multiple else clauses can be given in a single if statement
-Only one condition can be tested in a single if statement
- It is compulsory to give an else clause -Multiple elif clauses can be given in a single if statement
Answers
Answer:
- Multiple elif clause can be given in a single if statement - is the correct statement for the question.
Explanation:
Statement 1: Multiple else clause can be given in a single if statement.
The statement is absolutely false. An if statement cannot have multiple else statement. Also, its not mandatory to use else statement when we are working with only 1 condition.
Statement 2: Only one condition can be tested in a single if statement.
This statement is also false. We can check multiple conditions in a single if statement. Logical operators are useful in this case. We can combine multiple conditions at once.
Suppose, we are adding only positive even number in a list. Then we can code it as:
if number % 2 == 0 and number >= 0:
my_list.append(number)
In this way, we can check multiple conditions at once.
Statement 3: It is compulsory to give an else clause.
Its incorrect. We may/may not add an else clause in program. Sometimes, it's not necessary to work with else statement because we don't need it.
Statement 4: Multiple elif clause can be given in a single if statement.
Yes. Its true. We can add multiple elif statement with if statement. It is necessary when you are in a situation where two or more actions are performed depending on the conditions.