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
错误。我是在做错事还是只是以错误的方式看待它?
PriceList[0]
是一个花车。PriceList[0][1]
正在尝试访问浮点数的第一个元素。相反,做
PriceList[0] = PriceList[1] = ...code omitted... = PriceList[6] = PizzaChange
要么
PriceList[0:7] = [PizzaChange]*7
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句