Recall & Review
beginner
What is nested conditional execution in Python?
Nested conditional execution means putting one if-else statement inside another if or else block. It helps check multiple conditions step-by-step.
Click to reveal answer
beginner
How do you write a nested if statement in Python?
You write an if statement inside another if or else block, like:<br>
if condition1:
if condition2:
# code hereClick to reveal answer
beginner
Why use nested conditional execution?
It helps check detailed conditions in order. For example, first check if a person is adult, then check if they have a driving license.
Click to reveal answer
beginner
What happens if the outer condition in nested if is False?
The inner if statements are skipped completely because the outer condition controls if the inner code runs.
Click to reveal answer
beginner
Example: What will this code print?<br>
age = 20
if age >= 18:
if age >= 21:
print('Adult and can drink')
else:
print('Adult but cannot drink')
else:
print('Not an adult')It will print: Adult but cannot drink because age is 20, which is >= 18 but less than 21.
Click to reveal answer
What does nested conditional execution allow you to do?
✗ Incorrect
Nested conditional execution lets you check one condition inside another to handle complex decisions.
In nested if statements, when does the inner if run?
✗ Incorrect
The inner if runs only if the outer if condition is True, because it is inside that block.
What will this code print?<br>
score = 85
if score >= 90:
print('A grade')
else:
if score >= 80:
print('B grade')
else:
print('C grade')✗ Incorrect
Score is 85, so outer if is False, inner if is True, so it prints 'B grade'.
Which keyword is NOT used in nested conditional execution?
✗ Incorrect
'for' is a loop keyword, not used for conditional execution.
What is the main benefit of using nested conditionals?
✗ Incorrect
Nested conditionals help check related conditions one after another clearly.
Explain nested conditional execution and give a simple example.
Think about checking one condition inside another.
You got /2 concepts.
Describe how the flow of execution works in nested if statements.
Imagine opening boxes inside boxes only if the first box is open.
You got /3 concepts.