English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Funções no Python

Tipos de Dados do Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python program to find the largest number among three numbers

Python example大全

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.

Source code

# 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.

Python example大全