Write a program to find the largest of three numbers in Python
In this post, you will learn how to find the largest of three numbers using Python. Such type of programming can improve the thinking power of a new developer to tackle a given issue. There are different ways to find the largest of the three numbers.
Using if-else statement
In the given python program, we are taking input from the user. The user enters three numbers and program find the biggest among three numbers using if..elif..else statement.
# Python program to find the greatest of three numbers
# using if-else statement
x1 = int(input("Enter 1st number: "))
x2 = int(input("Enter 2nd number: "))
x3 = int(input("Enter 3rd number: "))
if(x1 >= x2) and (x1 >= x3):
largest = x1
elif(x2 >= x1) and (x2 >= x3):
greatest = x2
else:
greatest = x3
print("The greatest number is ",greatest )
Output of the above code -
Enter 1st number: 53
Enter 2nd number: 23
Enter 3rd number: 56
The greatest number is 56
Using max() function
Here, we have found the greatest among the three numbers using max() function -
# Python program to find the greatest of three numbers
# using max() function
x1 = int(input("Enter 1st number: "))
x2 = int(input("Enter 2nd number: "))
x3 = int(input("Enter 3rd number: "))
print(max(x1,x2,x3),"is the greatest number")
Output of the above code -
Enter 1st number: 34
Enter 2nd number: 21
Enter 3rd number: 75
75 is the greatest number
Related Articles
Convert list to dictionary Python
Convert array to list Python
numpy dot product
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple delimiters
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword