[英]NoneType after List Error
我無法理解第二個函數引發的錯誤。 當我通過第二個功能進行編程時,我意識到print(x)給了我:[['Anna',74.0],['Bill',65.0],['Cal',98.0]]無
由於沒有此限制,因此我無法遍歷該列表並將其設置為L。是什么原因引起的? 這是其他3個功能的粘貼框。 代碼在這里! 。 任何建議或朝正確方向的推動都將不勝感激。
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,為什么我的xa none type?
average_grade()
不返回列表,而是僅打印並返回None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.