Python Can';我无法找出代码中的小错误?
我的代码问题3和4:Python Can';我无法找出代码中的小错误?,python,Python,我的代码问题3和4: def avg_weight(diet, data): acc = [] grams = data.items() for (name , food , weights) in grams: if diet == food: acc.append([weights]) total = sum(acc) avg = total / len(acc) return avg 在上面,由于某种原因,acc.append([weig
def avg_weight(diet, data):
acc = []
grams = data.items()
for (name , food , weights) in grams:
if diet == food:
acc.append([weights])
total = sum(acc)
avg = total / len(acc)
return avg
在上面,由于某种原因,acc.append([weights])
行出现语法错误
三:
由于某种原因,我得到了一个随机的EOF错误
谢谢大家 如果您期望的输出是:
0:t
1:e
2:s
3:t
然后:
对于另一个问题,请提供您期望的输入是否可以先修复缩进?删除
权重周围的方括号
0:t
1:e
2:s
3:t
def word_positions (phrase):
str.split(phrase)
for num in range(0,len(phrase)) :
return str(num) + ":"+str(phrase[num])