In this program, we are going to find the largest number among three numbers, similar to the previous one, but it is nested if-else version.

Logic

Let three variables be: A = 400, B = 200 and C = 300

The logic goes like this:

  1. if A >= B then check for if A >= C, then print A else print C.
  2. else part: if B >= C then print B else print C.

See the below-shown flow diagram to better understand.

Program

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

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

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

# Find largest number
if num1 >= num2 :

    if num1 >= num3 :
        print("\n" + str(num1), "is largest number")
    else :
        print("\n" + str(num3), "is largest number")
    
else :

    if num2 >= num3 :
        print("\n" + str(num2), " is largest number")
    else :
        print("\n" + str(num3), " is largest number")

Output

Enter 1st number : 100
Enter 2nd number : 10
Enter 3rd number : 99
100 is largest number