3.Python program to find greatest of three numbers.
This Python example code demonstrates a simple Python program to find the greatest of three numbers using If and print the output to the screen. The primary purpose of this Python program is to explain to beginners how decision-making statements work.
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 n1
, n2
and n3
respectively. We’ve used the if...elif...else
ladder to find the largest among the three and display it.
n1 = int(input(“Please enter the first number (n1): “))
n2 = int(input(“Please enter the second number (n2): “))
n3 = int(input(“Please enter the third number (n3): “))
if n1 >= n2 and n1 >= n3:
print(“n1 is the greatest”)
elif n2 >= n1 and n2 >= n3:
print(“n2 is the greatest”)
else:
print(“n3 is the greatest”)
Output: –
Please enter the first number (n1): 45
Please enter the second number (n2): 60
Please enter the third number (n3): 100
n3 is the greatest