t=0
W=[2,2,2,3,3,3,5,5,5,5,8,8]
UW=[2,3,5,8]
Tfit=[12,24,25]
for j in range(len(UW)):
t = t+sum(W.count(UW[j])*max(Tfit)/len(W))
错误提示:Traceback (most recent call last):
File "C:/Users/zb/Desktop/compute.py", line 6, in <module>
t = t+sum(W.count(UW[j])*max(Tfit)/len(W))
TypeError: 'float' object is not iterable
去掉“/len(W)”时,显示:TypeError: 'int' object is not iterable
如果t每次for循环都要加进去,这么写
如果t不需要在for循环内部加,这么写