Page 96 - trackpad v5.1 class 8 flipbook
P. 96
else:
statement(s)
Program 2: To find the greatest number between two numbers
Program2.py
File Edit Format Run Options Window Help
#Program to compare two numbers using if else statement
a = int(input('Enter the first number: '))
b = int(input('Enter the second number: '))
if(a > b):
print('First number is greater than second number')
else:
print('Second number is greater than first number')
On running the above program, we get the following output:
Output
Enter the first number: 12
Enter the second number: 25
Second number is greater than first number
THE if-elif-else STATEMENT
Sometimes, we need to evaluate multiple
Start
statements to get a certain result. In
such scenarios, we can use the if-elif-else
statements to evaluate multiple scenarios. True
First, it checks and evaluates the first if condition 1 Statement 1
condition. If it is true, it will execute the False
respective statement(s). However, if
the condition is false, it moves to the elif True
if condition 2 Statement 2
statement and evaluates those conditions.
Finally, if none of the conditions evaluates to False
true, it executes the else block. The syntax of
if-elif-else statement is as follows: True
if condition 3 Statement 3
if (conditional expression):
statement(s) False
Statement
elif (conditional expression):
statement(s) Stop
94 Pro (V5.1)-VIII

