Page 108 - Trackpad_V1_Book 8_Flipbook
P. 108
Program 2: To check whether the entered number is even or odd
You will get the following output:
THE if-elif-else STATEMENT
Sometimes, we need to evaluate multiple statements to get a certain result. In such scenarios, we
can use the if-elif-else statements to evaluate multiple scenarios. First, it checks and evaluates
the first condition. If it is true, it will
execute the respective statement(s), but Test True
if the condition is false, it goes to the elif expression Statement 1
1
statement and evaluated those False
conditions. Finally, if none of the
conditions evaluates to true it executes Test True
the else block. The syntax of the expression Statement 2
2
if-elif-else statement is as follows:
False
if (conditional expression):
statement(s) Test True
expression Statement 3
elif (conditional expression): 3
statement(s) False
elif (conditional expression):
Body of else
statement(s)
else: Statement just
statement(s) below if-elseif
106 Trackpad (Version 1.0)-VIII

