Page 99 - KEC Khaitan C7 Flipbook
P. 99
On running the above program, we get the following output:
Output
Enter the first number: 84
Grade A
THE NESTED if STATEMENTS
Nested if statements mean if statements are Start
placed within another if statement. Python
allows us to write an if statement within
another if statement. The syntax of the nested False Statement 3
if statement is as follows: if condition 1
if (conditional expression1):
True
statement(s)
if (conditional expression2): if condition 2 False Statement 2
statement(s)
elif (conditional expression3):
statement(s) True
else: Statement 1
statement(s)
else:
Stop
statement(s)
Program 5: To determine which number is greater among three numbers
Program5.py
File Edit Format Run Options Window Help
#Program to determine which number is greater among three numbers
num1 = int(input('Enter the First Number: '))
num2 = int(input('Enter the Second Number: '))
num3 = int(input('Enter the Third Number: '))
if(num1>num2):
if(num1>num3):
print('First number is the greatest number.')
else:
print('Third number is the greatest number.')
else:
if(num2>num3):
print('Second number is the greatest number.')
else:
print('Third number is the greatest number.')
Control Structures in Python 97

