首页 > 解决方案 > 从 3 个数字中找出最大的数字

问题描述

我正在尝试使用 python3.6 找到最大的 3 个数字。但它返回错误的值。

#!/usr/bin/python3

a=input("Enter first number: ")
b=input("Enter second number: ")
c=input("Enter Third number: ")
if (a >= b) and (a >= c):
    largest=a
elif (b >= a) and (b >= c):
    largest=b
else:
    largest=c

print(largest, "is the greatest of all")

如果我提供,a=15;b=10 和 c=9 预期输出应为 15。

但我得到的实际输出为 9。

标签: pythonpython-3.x

解决方案


您可以使用 python 的 max() 内置函数: https ://www.freecodecamp.org/forum/t/python-max-function/19205


推荐阅读