Python Program to Find the Largest Among Three Numbers – 2024

Hey guys, in this blog we will see a Python Program to Find the Largest Among Three Numbers.

Code

# Python Program to Find the Largest Among Three Numbers


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

Enter first number: 12
Enter second number: 14
Enter third number: 16
The largest number is 16.0
Enter first number: 0
Enter second number: 0
Enter third number: 0
The largest number is 0.0
Enter first number: 2
Enter second number: 10
Enter third number: 9
The largest number is 10.0

Here we are simply using if/else to check the conditions:

  1. If num1 is greater than num2 and num3 both, then num1 is the largest number.
  2. If num2 is greater than num1 and num3 both, then num2 is the largest number.
  3. Else num3 is the largest number.

Check out our other python programming examples

Leave a Reply

Your email address will not be published. Required fields are marked *