Page 94 - ThinkGPT_V2.1_C7_Flipbook
P. 94
if…else Statement
The if…else statement checks for a condition. If the Start
condition evaluates to True, the indented block
following
the if statement is executed, otherwise the indented
if condition
block
False
after the else statement is executed.
True
Syntax: Statements in else
Statements in if
block execute
if (condition): block execute
Indented block
else: Stop
Indented block
Program: To compare two numbers and print the result.
On running the above program, you will get the following output:
Nested if Statement
A nested if in Python is an if statement placed inside another if statement. This structure allows
for more complex decision-making, where a second condition is checked only if the first condition is
true.
92 Premium Edition-VII

