Page 34 - tp_Modula_v2.0
P. 34
Program 2: To compare two numbers and print the result.
Program2.py
File Edit Format Run Options Window Help
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, you will get the following output:
Output
Enter the first number:6
Enter the second number:7
Second number is greater than first number
Enter the first number:6
Enter the second number:5
First number is greater than second number
NESTED IF STATEMENT
Python allows the nested if statement. This
Start
means the if indented block inside another
if…else indented block. The second nested if
False
indented block will run only when the first if if condition 1 Statement 3
condition evaluates to be true.
Syntax: True
if (conditional expression1): False
if condition 2 Statement 2
if (conditional expression2):
statement(s) True
else: Statement 1
statement(s)
else: Stop
statement(s)
32 Touchpad MODULAR (Version 2.0)

