Python Program to find out Largest among three numbers
The largest number among three numbers using four methods. 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.
Frequency of Word in a python List
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
These are typical solution that you may have seen in different websites but I the last one is specific to Python that you can not implement in other programming languages.
The Largest number among three numbers
l1 = [10, 23, 45] l1.sort() print(l1[-1])
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.