Page 134 - Plus V4 with Adobe class 7
P. 134
Nested if Statement
Python allows the nested if statement. This means the if indented block inside another if…else indented
block. The second nested if indented block will run only when the first if condition evaluates to be true.
The syntax of nested if statement is shown below:
Syntax: False
Test Expression 1 Statement 3
if (Test Expression1):
if (Test Expression2): True
Indented block 1
False
else: Test Expression 2 Statement 2
Indented block 2
True
else:
Indented block 3 Statement 1
Program 5: To find out if the student is selected for the college or not based on the given conditions –
1. Selected if age > 18 and marks > 65
2. Not selected if age > 18 and marks < 65
3. Not selected if age < 18
On running the program given on previous page, we get the following output:
132 Plus (Ver. 4.0)-VII

