Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在数字a、b、c中最大_Python 3.x_Python 3.6_Python 3.7 - Fatal编程技术网

Python 3.x 在数字a、b、c中最大

Python 3.x 在数字a、b、c中最大,python-3.x,python-3.6,python-3.7,Python 3.x,Python 3.6,Python 3.7,毫无疑问,greater1,1可能返回equal,因此您随后调用greatestequal,1,1,使您将字符串与整数进行比较。您尝试将字符串equal与1进行比较,而不是equal,您可以返回a或b,因为它们具有相同的值。 def greater(a,b): if a > b: return a elif a==b: return "equal" else: return b def greatest(a,b,c)

毫无疑问,greater1,1可能返回equal,因此您随后调用greatestequal,1,1,使您将字符串与整数进行比较。

您尝试将字符串equal与1进行比较,而不是equal,您可以返回a或b,因为它们具有相同的值。
def greater(a,b):
    if a > b:
        return a
    elif a==b:
        return "equal"
    else:
        return b

def greatest(a,b,c):

    if a>b and a>c:
        return 'a'

    elif a==b and a==c:
        return "equal"

    elif b > a and b > c:
        return b

    elif b==a and b==c:
        return "equal"

    elif c==a and c==b:
        return "equal"

    else:
        return c

bigger = greater(1,1)        
biggest = greatest(bigger,1,1)
print(biggest)


error:Traceback (most recent call last):
  File "functions_execrise2.py", line 30, in <module>
    biggest = greatest(bigger,1,1)
  File "functions_execrise2.py", line 11, in greatest
    if a>=b and a>=c:
TypeError: '>=' not supported between instances of 'str' and 'int'