2024-05-04 19:14:28 发布
网友
计算和后列表是否为空??
t = int(input()) while t > 0: n,m=map(int,input().split()) a=map(int,input().split()) l,o=sum(a),max(a) print(l) if ((o * n)-l) == m: print("YES") else: print((o * n)-l) print("NO") t = t-1
在Python 3中,map()返回一个迭代器(与Python 2不同)。sum()函数已经遍历了所有结果,迭代器现在为空:
map()
sum()
>>> sample = '1 2 3' >>> map(int, sample.split()) <map object at 0x10523b2e8> >>> a = map(int, sample.split()) >>> list(a) [1, 2, 3] >>> list(a) []
使用list()将结果复制到列表对象,或者使用列表理解而不是map():
list()
a = [int(i) for i in input().split()]
像这样试试:
inputparam='100 2 300' a = [int(i) for i in inputparam.split()] maxNo=max(a) sumno=sum(a)
在Python 3中,
map()
返回一个迭代器(与Python 2不同)。sum()
函数已经遍历了所有结果,迭代器现在为空:使用
list()
将结果复制到列表对象,或者使用列表理解而不是map()
:像这样试试:
相关问题 更多 >
编程相关推荐