0
0
Pythonprogramming~5 mins

Nested conditional execution in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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 here
Click 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?
ARun code without any condition
BWrite only one condition
CSkip all conditions
DCheck multiple conditions inside each other
In nested if statements, when does the inner if run?
AOnly if the outer if condition is True
BAlways, no matter what
COnly if the outer if condition is False
DNever
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')
AA grade
BB grade
CC grade
DNo output
Which keyword is NOT used in nested conditional execution?
Afor
Belse
Celif
Dif
What is the main benefit of using nested conditionals?
AAvoid using else statements
BMake code run faster
CSimplify checking multiple related conditions stepwise
DWrite fewer lines of code
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.