wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

if...elif in Python

Total questions: 5

Worksheet time: 3mins

Name
Class
Date
1.

What is the key difference between using multiple if statements versus using if..elif statements?

a)

Multiple if statements allow only one condition to be checked, while if..elif allows for multiple conditions.

b)

if..elif statements are more efficient in terms of runtime compared to using multiple if statements.

c)

if..elif statements allow only one condition to be checked, while multiple if statements allow for multiple conditions.

d)

There is no difference; they both achieve the same outcome.

2.

In an if..elif statement, if the condition in the if block evaluates to False, what happens next?

a)

The code inside the if block is executed, and the program exits the if..elif statement.

b)

The code inside the if block is executed, and the program continues to check the conditions in the subsequent elif blocks.

c)

The code inside the if block is skipped, and the program moves to the next elif block.

d)

The code inside the if block is skipped, and the program exits the if..elif

3.

What happens if there are multiple conditions in an if..elif statement that evaluate to True?

a)

All corresponding blocks of code are executed.

b)

Only the block of code associated with the first True condition is executed, and the rest are skipped.

c)

An error occurs because there should be only one True condition.

d)

The program executes the else block.

4.

What is the purpose of using elif instead of multiple if statements?

a)

It makes the code more readable and concise.

b)

It allows for nested conditionals within each elif block.

c)

It speeds up the execution of the code.

d)

It prevents the need for an else block.

5.

When should you use else in conjunction with if..elif statements?

a)

When there is only one condition to check.

b)

When you want to execute a block of code if none of the previous conditions are True.

c)

When you want to avoid using elif.

d)

When you want to nest another if statement within the current if block