Python | Find largest of three number using nested if else

Python | Nested if else example: Here, we are implement a program, it will input three numbers and find the largest of three numbers. By Pankaj Singh Last updated : December 20, 2023

Problem statement

Input three integer numbers and find the largest of them using nested if else in python.

Example

Input:
Enter first number: 10
Enter second number: 20
Enter third number: 5

Output:
Largest number: 20

Program for largest of three numbers in Python

# input three integer numbers
a = int(input("Enter A: "))
b = int(input("Enter B: "))
c = int(input("Enter C: "))

# conditions to find largest
if a > b:
    if a > c:
        g = a
    else:
        g = c
else:
    if b > c:
        g = b
    else:
        g = c

# print the largest number
print("Greater  = ", g)

Output

RUN 1:
Enter A: 10
Enter B: 20
Enter C: 5
Greater  =  20

RUN 2:
Enter A: -10
Enter B: -20
Enter C: -30
Greater  =  -10

RUN 3:
Enter A: -10
Enter B: 10
Enter C: 10
Greater  =  10

In this example, we have used the following Python topics that you should learn:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.