0
我无法理解第二个函数引发的错误。当我通过第二功能黑客我实现打印(X)给我: [ '安娜',74.0],[ '比尔',65.0],[ 'CAL',98.0] 无列表错误后的无类型
由于到这个没有,我无法遍历列表并将其设置为L.什么导致这没有?这是另外3个功能的粘贴箱。 code here!。任何意见或推动正确的方向非常感谢。
def string_avg(L):
'''(list of str) -> list of list
Given a list of strings where each string has the format:
'name, grade, grade, grade, ...' return a new list of
lists where each inner list has the format :
[name (str), average grade (float)]
Requirement: This function should be 1 line long.
>>> string_avg(['Anna, 50, 92, 80', 'Bill, 60, 70', 'Cal, 98.5, 100, 95.5,
98'])
[['Anna', 74.0], ['Bill', 65.0], ['Cal', 98.0]]
'''
return(average_grade((string_list(L))))
def string_avg_update(L):
'''(list of str) -> NoneType
Given a list of strings where each string has the format:
'name, grade, grade, grade, ...' update the given
list of strs to be a list of floats where each item
is the average of the corresponding numbers in the
string. Note this function does NOT RETURN the list.
>>> L = ['Anna, 50, 92, 80', 'Bill, 60, 70', 'Cal, 98.5, 100, 95.5, 98']
>>> string_avg_update(L)
>>> L
[74.0, 65.0, 98.0]
'''
x = string_avg(L)
我打算代码的最后一个函数是:
Say I changed the last function code to:
x = string_avg(L)
for i in range(0,len(x)):
L[i] = x[i][1]
但它说我找不到nonetype的LEN,为什么我的X一无类型?
假如你运行你写到文档的文档测试?结果是什么? –
'x = string_avg(L)'设置一个局部变量'x',当函数结束时这个变量不会被使用。 –
@MichaelButscher我得到了['安娜,50,92,80','比尔,60,70','Cal,98.5,100,95.5,98']回到我的第二个功能(这与输入)以及所有其他功能的预期结果。我的目标是找出什么导致没有,然后设置L [每个索引] = x [每个索引] [1]。 –