Page 104 - TP_V5.1_C7_fb
P. 104
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')
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 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). However, if the Start
condition is false, it moves to the elif statement
and evaluates those conditions. Finally, if True
none of the conditions evaluate to true, it if condition 1 Statement 1
executes the else block. The syntax of the
if-elif-else statement is as follows: False
if (conditional expression): True
if condition 2 Statement 2
statement(s)
elif (conditional expression): False
statement(s)
True
elif (conditional expression): if condition 3 Statement 3
statement(s)
False
else: Statement
statement(s)
Stop
102 Premium Edition-VII

