Page 132 - TechPluse_C8_Flipbook
P. 132
Program 6: To check if the given number is lucky or not, if the given number is greater than zero
and is even, then print ‘Lucky number’ else print ‘Not a lucky number’.
On running the above program, we get the following output:
The if…elif…else Ladder
The if…elif…else ladder is another
type of if statement. It helps us to test
True
multiple conditions and follows a top- Test Expression 1 Statement 1
down approach. In this, as soon as the
condition of the if evaluates to be true, False
the indented block associated with that
True
‘if’ is executed, and the rest of the ladder Test Expression 2 Statement 2
is avoided. If none of the conditions
evaluates to true, then the final else False
statement gets executed.
True
The syntax of if...elif...else ladder is shown Test Expression 3 Statement 3
below:
False
Syntax: Body of else
if (Test Expressions_1):
Statement just below
Indented block 1
if...elif...else ladder
130 Premium Edition-VIII

