【发布时间】:2020-01-17 21:38:43
【问题描述】:
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'
【问题讨论】:
-
您正在尝试将字符串
"equal"与1进行比较 -
您可以返回
a或b而不是"equal",因为它们具有相同的值。
标签: python-3.x python-3.6 python-3.7