Page 133 - Plus_V2.2_C7_Flipbook
P. 133
On running the above program, we get the following output:
Let’s CatCh uP
Find the error in the following code and rewrite the code.
if(age > 18)
print(‘You are eligible to vote’)
else:
print(‘Not eligible to vote’)
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
if (Test Expression1):
Test Expression 1 Statement 3
if (Test Expression2):
Indented block 1 True
else:
False
Indented block 2 Test Expression 2 Statement 2
else:
True
Indented block 3
Statement 1
Conditional Statements in Python 131

