Though there are many approaches to find largest number among two numbers. In this article, we will show you, How to write a Python program to find largest of Two Numbers using Elif Statement and Nested If statement.

## Python Program to find Largest of Two Numbers using Elif Statement

This python program for largest of two numbers helps user to enter two different values. Next, it will find the largest number among those two numbers using Elif Statement

# Python Program to find Largest of Two Numbers a = float(input(" Please Enter the First Value a: ")) b = float(input(" Please Enter the Second Value b: ")) if(a > b): print("{0} is Greater than {1}".format(a, b)) elif(b > a): print("{0} is Greater than {1}".format(b, a)) else: print("Both a and b are Equal")

**OUTPUT**

First, we entered the values a = 10, b = 20

Next, we entered the values a = 10, and b = 10

At last, we entered the values a = 25, b = 15

**ANALYSIS**

Within this Python Program to find Largest of Two Numbers example, the following statements ask users to enter two numbers, and stores them in variables a, and b

a = float(input(" Please Enter the First Value a: ")) b = float(input(" Please Enter the Second Value b: "))

Else If Statement

if(a > b): print("{0} is Greater than {1}".format(a, b)) elif(b > a): print("{0} is Greater than {1}".format(b, a)) else: print("Both a and b are Equal")

- First if condition check whether a is greater than b. If True then a is greater than b will be printed
- Elif statement check whether b is greater than a. If True then b is greater than a will be printed
- If all the above conditions fail, it means they are equal.

## Python Program to find Largest of Two Numbers using Nested If Statement

In this Python program, it will find largest number among two using Nested If.

# Python Program to find Largest of Two Numbers a = float(input(" Please Enter the First Value a: ")) b = float(input(" Please Enter the Second Value b: ")) if(a == b): print("Both a and b are Equal") else: largest = a if a > b else b print("{0} is the Largest Value".format(largest))

**OUTPUT **

**OUTPUT 2**

**OUTPUT 3**

Within this Python Program to find Largest of Two Numbers example, First if condition check whether a is equal to b. Inside the Else block, we are using another if statement to check whether a is greater than b or not.

## Python Program to find Largest of Two Numbers using Arithmetic Operator

In this Python Largest of Two Numbers example, we are using Minus operator

# Python Program to find Largest of Two Numbers a = float(input(" Please Enter the First Value a: ")) b = float(input(" Please Enter the Second Value b: ")) if(a - b > 0): print("{0} is Greater than {1}".format(a, b)) elif(b - a > 0): print("{0} is Greater than {1}".format(b, a)) else: print("Both a and b are Equal")

**OUTPUT**

**OUTPUT 2**

**OUTPUT 3**