2017-10-13 3 views
0

2番目の関数から発生したエラーの理解に問題があります。私はプリントを実現し第二の機能によってハッキングされたとおり(x)は私を与える: [[ 'アンナ'、74.0]、[ 'ビル'、65.0]、[ 'カル'、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はなしタイプですか?

+0

はあなたがドキュメントに書いたdoctestを実行していたら返していないのですか?結果は何でしたか? –

+0

'x = string_avg(L)'は、関数が終了すると未使用で失われるローカル変数 'x'を設定します。 –

+0

@MichaelButscher 2番目の関数(「Anna、50、92、80」、「Bill、60,70」、「Cal」、98.5,100,95.5,98 ')が返されました。入力)および他のすべての機能の期待される結果。私の目標は、noneを引き起こす原因を見つけ出し、L [すべてのインデックス] = x [各インデックス] [1]を設定することです。 –

答えて

0

average_grade()はリストを返すだけで、それを印刷し、None

+0

これはまさに問題でした。それは私によって右に滑った。どうもありがとうございます! –

関連する問題