English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this program, you will learn to use if to find the largest of the three numbers and display it.
To understand this example, you should understand the followingPython programmingTopic:
In the following plan, the three numbers are stored in num1, num2and num3respectively. We have used if...elif...else statements to find the largest of the three numbers and display it.
# Python program to find the largest of three input numbers # Change num1, num2and num3value # For different results num1 = 10 num2 = 14 num3 = 12 # Uncomment the following line to get three numbers from the user #num1 = float(input("Enter the first number: ")) #num2 = float(input("Enter the second number: ")) #num3 = float(input("Enter the 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 result
The largest number is 14.0
Note:To test the program, you can modify num1, num2and num3value.