Although We have many approaches to find largest number among three numbers. In this article we will show you, How to write a Python program to find largest of three numbers using Elif Statement and Python Nested If.

## Python Program to find Largest of Three numbers using Elif Statement

This program helps the user to enter three different values and then it will find the largest number among that three numbers using Python Elif Statement

**PYTHON CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Python Program to find Largest of Three Numbers using Elif Statement a = float(input("Please Enter the First value: ")) b = float(input("Please Enter the First value: ")) c = float(input("Please Enter the First value: ")) if (a > b and a > c): print("{0} is Greater Than both {1} and {2}". format(a, b, c)) elif (b > a and b > c): print("{0} is Greater Than both {1} and {2}". format(b, a, c)) elif (c > a and c > b): print("{0} is Greater Than both {1} and {2}". format(c, a, b)) else: print("Either any two values or all the three values are equal") |

**ANALYSIS**

Following statements ask the user to enter three numbers and stores the user entered values in variables a, b and c

1 2 3 |
a = float(input("Please Enter the First value: ")) b = float(input("Please Enter the First value: ")) c = float(input("Please Enter the First value: ")) |

First if condition check whether a is greater than b and a is greater than c. If both of these are True then following print statement will be displayed (a is greater than both b, c).

1 2 |
if (a > b and a > c): print("{0} is Greater Than both {1} and {2}". format(a, b, c)) |

First Elif statement check whether b is greater than a and b is greater than c. If both of these are True then following print statement will be displayed ( b is greater than both a, c).

1 2 |
elif (b > a and b > c): print("{0} is Greater Than both {1} and {2}". format(b, a, c)) |

Second Elif statement check whether c is greater than a and c is greater than b. If both of these are True then following print statement will be displayed ( c is greater than both a, b).

1 2 |
elif (c > a and c > b): print("{0} is Greater Than both {1} and {2}". format(c, a, b)) |

If all the above conditions fail, it means they are equal.

1 |
print("Either any two values or all the three values are equal") |

**OUTPUT: **

First, we entered the values a = 12, b = 4, c= 6 and Next, we entered the values a = 19, b = 25, c= 20 and Next, we entered the values a = 45, b = 36, c= 96 and Finally, we entered the values a = 5, b = 5, c= 5

## Python Program to find Largest of Three numbers using Nested If Statement

This program helps the user to enter three different values and then it will find the largest number among that three numbers using Python Nested If.

**PYTHON CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Python Program to find Largest of Three Numbers using Nested If Statement a = float(input("Please Enter the First value: ")) b = float(input("Please Enter the First value: ")) c = float(input("Please Enter the First value: ")) if (a-b > 0) and (a-c > 0): print("{0} is Greater Than both {1} and {2}". format(a, b, c)) else: if(b - c > 0): print("{0} is Greater Than both {1} and {2}". format(b, a, c)) else: print("{0} is Greater Than both {1} and {2}". format(c, a, b)) |

**ANALYSIS**

Following statements ask the user to enter three numbers and stores the user entered values in variables a, b and c

1 2 3 |
a = float(input("Please Enter the First value: ")) b = float(input("Please Enter the First value: ")) c = float(input("Please Enter the First value: ")) |

First if condition check whether a-b is greater than 0 and a-c is greater than 0. If we subtract small number from big number then this condition fail, otherwise it will be True. If this condition is True then a is greater than both b, c.

1 2 |
if (a-b > 0) and (a-c > 0): print("{0} is Greater Than both {1} and {2}". format(a, b, c)) |

Else statement will execute when the first If condition is False so, there is no need to check for a value. In the Else statement we are inserting one more if condition (Nested IF) to check whether b-c is greater than 0. If this condition is True then b is greater than both a, c.

1 2 3 |
else: if(b - c > 0): print("{0} is Greater Than both {1} and {2}". format(b, a, c)) |

Else c is greater than both a, b.

1 |
print("{0} is Greater Than both {1} and {2}". format(c, a, b)) |

**OUTPUT **

First, we entered the values a = 32, b = 45, c= 98 and Next, we entered the values a = 22, b = 5, c= 7 and FInally, we entered the values a = 56, b = 222, c= 98

Thank You for Visiting Our Blog

## Leave a Reply