私はちょうどPythonを学び始めました。そして、私は特定の機能を絞って問題を抱えています。基本的に、この関数は金利を追加してリストを更新する必要があります。
lst = [[25, 10, 300], [7, 30, 80], [7, 530, 24],[65, 30, 2]]
rate = [0.5, 0.02, 0.15]
出力:
[37.5, 10.2, 345.0]
[10.5, 30.6, 92.0]
[10.5, 540.6, 27.6]
[97.5, 30.6, 2.3]
これまで私がこれまで持っていたことは次のとおりです。
def multiply(lst, rate):
for i in range(len(lst)):
lst[i] += rate[i] * lst[i]
エラーメッセージが表示されます。 “TypeError:型
‘float’の非intでシーケンスを掛けることはできません”
ありがとうございました
ベストアンサー
lst[i]
is a list of numbers, not a number itself.
You can’t multiply a list of numbers by a number, but you can
multiply the elements in the list by the number.