Method: First use the input() function to receive the three numbers input from the keyboard; then use the float() or int() function to uniformly convert the three received values into floating point numbers or integers; then use " if else" statement compares the sizes of three numbers to obtain the maximum number; finally use the print() function to output the maximum number.
The operating environment of this tutorial: windows7 system, Python3, Dell G3 computer.
In python, you can use the input() function to input three numbers, and use the float() (or int()) function, print() function and "if else" statement to find the maximum value and output it. .
Implementation idea:
The input() function receives three numbers input from the keyboard;
float() or int() function uniformly converts the three received values into floating point numbers or integers;
The "if else" statement compares the sizes of the three numbers to obtain the maximum Number;
#print() function outputs the maximum number.
Implementation code: input three numbers and output the largest number among the three numbers
# 第一种写法: num1 = float(input('请输入第一个数:')) num2 = float(input('请输入第二个数:')) num3 = float(input('请输入第三个数:')) if num1 < num3 and num2 < num3: big_num = num3 elif num1 < num2 and num3 < num2: big_num = num2 else: big_num = num1 print('三个数中最大数为:%s' % big_num) # 第二种写法(工作量会指数级增加): n1= int(input('please enter the firest number:')) n2 = int(input('please enter the second number:')) n3 = int(input('please enter the third number:')) max_num = 0 if n1 > n2: max_num = n1 if n1 > n3: max_num = n1 else: max_num = n3 else: max_num = n2 if n2 > n3: max_num = n2 else: max_num = n3 print('the max_num is:%d'%max_num) # 第三种写法(最简写法): num1 = float(input('请输入第一个数:')) num2 = float(input('请输入第二个数:')) num3 = float(input('请输入第三个数:')) max_num = num1 # 先假设num1最大 if max_num < num2: max_num = num2 if max_num < num3: max_num = num3 print('最大数是:%f' % max_num)
Related function description
The input() function in Python3.x accepts a standard input data and returns it as string type.
int() function is used to convert a string or number into an integer.
float() function is used to convert integers and strings into floating point numbers.
【Related recommendations: Python3 video tutorial】
The above is the detailed content of How to input three numbers in python and output the largest value. For more information, please follow other related articles on the PHP Chinese website!