Python Program to find out Largest among three numbers

In this article, we will learn how to find out the largest number among the three given numbers. These methods are totally different from each other but as a computer science student, you must have the idea.

The largest number using if-else [ multiple checking ]

a = int(input('Enter first number :'))
b = int(input('Enter second number :'))
c = int(input('Enter third number :'))
if(a>b):
    if(a>c):
       print(a,' is the largest number')
    else:
       print(c,' is the largest number')
else:
   if(b>c):
       print(b,'is the largest number')
   else:
      print(c,' is the largest number')

The largest number – Second method

a = int(input('Enter first number :'))
b = int(input('Enter second number :'))
c = int(input('Enter third number :'))
lar = a
if(lar<b):
   lar = b
if(lar<c):
   lar = c
print(lar,' is the largest number')

The output of the above programs are as follows

Enter first number :4
Enter second number :56
Enter third number :3
56  is the largest number

Enter first number :45
Enter second number :3
Enter third number :56
56  is the largest number

The largest number – third method

a = int(input('Enter first number :'))
b = int(input('Enter second number :'))
c = int(input('Enter third number :'))
if(a > b and a > c):
    print(a, ' is the largest number')

if(b > a and b > c):
    print(b, ' is the largest number')

if(c > b and c > a):
    print(c, ' is the largest number')

The above largest number program uses logical operators to combine two python expressions using and operator.
The output is as follow

Enter first number :2
Enter second number :45
Enter third number :6
45  is the largest number

Now, I think you have the idea that for any problem we have multiple solutions. I hope you like these simple solutions to find out largest number among the three numbers.

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.