Python 3.x 在数字a、b、c中最大
毫无疑问,greater1,1可能返回equal,因此您随后调用greatestequal,1,1,使您将字符串与整数进行比较。您尝试将字符串equal与1进行比较,而不是equal,您可以返回a或b,因为它们具有相同的值。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)
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'