Find the Largest Among Three Numbers

Course- Python >

Source Code


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

# take three numbers from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 > num2) and (num1 > num3):
   largest = num1
elif (num2 > num1) and (num2 > num3):
   largest = num2
else:
   largest = num3

print("The largest number is",largest)

Output 1


Enter first number: 10
Enter second number: 12
Enter third number: 14
The largest number is 14.0

Output 2


Enter first number: -1
Enter second number: 0
Enter third number: -3
The largest number is 0.0

 

In this program, we ask the user to input three numbers. We use the if...elif...else ladder to find the largest among the three and display it.