TypeError: 'float' オブジェクトは添字付けできません 質問する

TypeError: 'float' オブジェクトは添字付けできません 質問する
PizzaChange=float(input("What would you like the new price for all standard pizzas to be? "))      
PriceList[0][1][2][3][4][5][6]=[PizzaChange]  
PriceList[7][8][9][10][11]=[PizzaChange+3]

基本的に、ユーザーが数値 (浮動小数点入力) を入力する入力があり、前述のリスト インデックスがすべてその値に設定されます。何らかの理由で、次のことをしないと設定できません。

TypeError: 'float' object is not subscriptable

エラーです。何か間違ったことをしているのでしょうか、それとも単に見方が間違っているだけでしょうか?

ベストアンサー1

PriceList[0]は浮動小数点数です。PriceList[0][1]浮動小数点数の最初の要素にアクセスしようとしています。代わりに、

PriceList[0] = PriceList[1] = ...code omitted... = PriceList[6] = PizzaChange

または

PriceList[0:7] = [PizzaChange]*7

おすすめ記事