In this program, we are going to see how to find the largest number among three numbers using if statement.

Logic

Here we have to compare each number with another two numbers, if it is greater than the both then simply print it.

Let’s say A = 11, B = 22 and C = 15

Then steps would be

  1. if A > B and A > C that means A is the largest number.
  2. if B > A and B > C that means B is the largest number.
  3. Similarly if C > A and C > B that means C is the largest number.

Program

# Take 3 numbers from user
num1 = int(input("Enter 1st number : "))

num2 = int(input("\nEnter 2nd number : "))

num3 = int(input("\nEnter 3rd number : "))

# Check for number 1
if num1 >= num2 and num1 >= num3 :
    print("\n" + str(num1), "is largest number")

# Check for number 2
if num2 >= num1 and num2 >= num3 :    
    print("\n" + str(num2), "is largest number")

# Check for number 3
if num3 >= num1 and num3 >= num2 :
    print("\n" + str(num3), "is largest number")

Output

Enter 1st number : 10
Enter 2nd number : 5
Enter 3rd number : 11
11 is largest number