When an if-else statement is executed in the body of another if-else statement, it is called nested.
Line | Description |
---|---|
1 | Initializes the variable number with the value 56 |
3 | If the value of number is less than or equal to 100 |
4 – 5 | If the value of number is less than 50, print the string “Value is smaller than 50” |
6 – 7 | If the value of number is less than 50, print the string “Value is 50” |
8 – 9 | Otherwise the string “Value is between 51 und 100“ is output |
10 – 11 | If the value of number is greater than 100 output the following string “Value is greater than 100” |
number = 56
if (number <= 100):
if (number < 50):
print("Value is smaller than 50")
elif (number == 50):
print("Value is 50")
else:
print("Value is between 51 und 100")
else:
print("Value is greater than 100")
Value is between 51 und 100