001-输入三个数值,输出其中的最大值和最小值
方法一: print("Number1、Number2、Number3只能输入3个数字") number1 = float(input("Number1= ")) number2 = float(input("Nnmber2= ")) number3 = float(input("Number3= ")) if number1 >= number2 >= number3: print("最大值为:",number1) print("最小值为:",number3) elif number3 >= number1 >= number2: print("最大值为:",number3) print("最小值为:",number2) elif number1 >= number3 >= number2: print("最大值为:",number1) print("最小值为:",number2) elif number2 >= number1 >= number3: print("最大值为:",number2) print("最小值为:",number3) elif number3 >= number2 >= number1: print("最大值为:",number3) print("最小值为:",number1) else: print("最大值为:",number2) print("最小值为:",number1) 方法二: print("Number1、Number2、Number3只能输入3个数字") number1 = float(input("Number1= ")) number2 = float(input("Nnmber2= ")) number3 = float(input("Number3= ")) max_number = 0 if number1 >= number2: max_number = number1 if number3 >= max_number: print("最大值为:",number3) else: print("最大值为:",max_number) else: max_number = number2 if number3 >= max_number: print("最大值为:", number3) else: print("最大值为:", max_number)