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 Inheritance
Python Program to Find Sum of Natural Numbers Using Recursion
How to Get Started With Python?
Python pow()
Python Program to Find Numbers Divisible by Another Number
Python Operators
Python Decorators
Python Program to Check Whether a String is Palindrome or Not
Python complex()
Python delattr()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python compile()
Python Program to Find the Factors of a Number
Python Input, Output and Import
Python File I/O Operation
Python Program to Get the Class Name of an Instance
Python id()
Deep Learning with Python - Francois Chollet
Python exec()
Debug a JavaMail Program
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Transpose a Matrix
Python Anonymous / Lambda Function
Python String isdigit()
Python Dictionary clear()
Python Get Current time
Python next()
Python Program to Solve Quadratic Equation
Python Set intersection()
Python String lower()
Python Namespace and Scope
Python String startswith()