2.4.1.5 Nested and Chained Conditionals
Python Programming
Sometimes, we need to check multiple conditions inside another condition. This is called nesting.
python
# Syntax of nested if statement
if condition1:
if condition2:
# code to run if both condition1 and condition2 are true
else:
# code to run if condition1 is true but condition2 is false
else:
# code to run if condition1 is falseExample: If the weather is rainy and the temperature is below 15 degrees, we wear a raincoat. If it is only rainy, we take an umbrella. If the weather is not rainy, we just enjoy the day.
python
weather = "rainy"
temperature = 10