Python Program to Find Largest among Three Numbers

Problem: Write a python program to find largest number among three input numbers.

Solution:
Python program to find largest among three numbers
  1. Accept three numbers from user.
  2. Use conditional statement if to check whether first number larger than other two.
  3. If first condition doe not meet, check whether second number is larger than other two.
  4. If the second condition also does not meet then the third number is the largest among three given numbers.

Python program to find largest among three numbers

# Python program to find the largest number among the three numbers

number1 = float(input("Enter first number: "))
number2 = float(input("Enter second number: "))
number3 = float(input("Enter third number: "))

if (number1 >= number2) and (number1 >= number3):
   largest = number1
elif (number2 >= number1) and (number2 >= number3):
   largest = number2
else:
   largest = number3
print("The largest number among three numbers is", largest)

Output:

Enter first number: 11
Enter second number: 22
Enter third number: 33
The largest number among three numbers is 33.0
You can also write above python code as little as one line.
number1 = float(input("Enter first number: "))
number2 = float(input("Enter second number: "))
number3 = float(input("Enter third number: "))

largest = max(number1, number2, number3)
print("The largest among three numbers is ", largest)