错误信息是:
追溯(最近一次通话):
在elif findMinAndMax([7])!=(7,7)中的文件“ C:/ 1-Python / 2-projects /最值.py”,第18行:
文件“ C:/ 1-Python / 2-projects /最值.py”,第7行,位于L的findMinAndMax for i中:
TypeError:无法解压缩不可迭代的int对象
我的密码
def findMinAndMax(L):
if L == []:
return (None, None)
else:
max1 = L[0]
min1 = L[0]
for i, in L:
if i >= max1:
max1 = i
elif i <= min1:
min1 = i
return (min1, max1)
if findMinAndMax([]) != (None, None):
print('test failed!')
elif findMinAndMax([7]) != (7, 7):
print('test failed!!')
elif findMinAndMax([7, 1]) != (1, 7):
print('test failed!!')
elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9):
print('test failed!!')
else:
print('test success!!')
只需在for循环中删除逗号:
...
for i in L:
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句