In this program, you’ll learn to find the largest among three numbers using if else and display it.
To understand this example, you should have the knowledge of the following Python programming topics:
In the program below, the three numbers are stored in num1, num2 and num3 respectively. We’ve used the if...elif...else ladder to find the largest among the three and display it.
Source Code
# Python program to find the largest number among the three input numbers
# change the values of num1, num2 and num3
# for a different result
num1 = 10
num2 = 14
num3 = 12
# uncomment following lines to take three numbers from user
#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
The largest number is 14.0
Note: To test the program, change the values of num1, num2 and num3.
Related posts:
Python Program to Calculate the Area of a Triangle
Python Program to Copy a File
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python iter()
Python Machine Learning - Sebastian Raschka
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Introduction to Scientific Programming with Python - Joakim Sundnes
Python round()
Python len()
Python str()
Python Set update()
Python Set intersection_update()
Python Input, Output and Import
Python Program to Find the Factorial of a Number
Python Program to Reverse a Number
Python Program to Merge Mails
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary fromkeys()
Python Program to Check Whether a String is Palindrome or Not
Python Set difference()
Python String strip()
Python input()
Python enumerate()
Python super()
Python Program to Access Index of a List Using for Loop
Python Program to Find ASCII Value of Character
Python Program to Count the Number of Digits Present In a Number
How to Get Started With Python?
Python Set symmetric_difference()
Python list()
Python String encode()
Python locals()