Code

    
weather = "sunny"
time_of_day = "afternoon"
if weather == "sunny":
    if time_of_day == "morning":
        activity = "jog"
    elif time_of_day == "afternoon":
        activity = "picnic"
    else:
        activity = "sunset"
elif weather == "rainy":
    activity = "enjoy the rain"  
else:   
    activity = "indoor games"  
    
            

Memory Analogy

Visual Analogy

Explanation

This example demonstrates how if-elif statements work in Python. The conditional checks stop as soon as one of the conditions is satisfied. In this case, the first condition checks if the weather is 'sunny', and since it is true, the next condition inside checks if the time_of_day is 'afternoon'. When both conditions are true, the code assigns the activity to 'picnic'. Only this block of code runs, and the elif and else conditions are skipped because the first condition matched.

Step 0