Page 114 - Touchpad_Plus_V3.2_Class 7
P. 114
THE IF...ELSE STATEMENT
The if…else statement checks for a condition. If Start
the condition evaluates to True, the indented block
following the if statement is executed; otherwise, the
indented block after the else statement is executed.
if condition
The syntax of the if…else statement is given below: False
True
Syntax: Statements in else
Statements in if
if (Test Expression): block execute
block execute
Indented block
else:
Stop
Indented block
Program 3: To compare two numbers and print the result.
Program3.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: 45
Enter the second number: 65
Second number is greater than first number
Enter the first number: 38
Enter the second number: 22
First number is greater than second number
112 Plus (Ver. 3.2)-VII

