本文介紹了TypeError:“浮動"對象不可下標的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
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]
基本上,我有一個輸入,用戶將輸入一個數字值(浮點輸入),然后它將所有上述列表索引設置為該值.出于某種原因,我無法在沒有提出以下建議的情況下設置它們:
Basically I have an input that a user will put a number values (float input) into, then it will set all of these aforementioned list indexes to that value. For some reason I can't get it to set them without coming up with a:
TypeError: 'float' object is not subscriptable
錯誤.我做錯了什么還是我只是看錯了?
error. Am I doing something wrong or am I just looking at it the wrong way?
推薦答案
PriceList[0]
是一個浮點數.PriceList[0][1]
正在嘗試訪問浮點數的第一個元素.相反,做
PriceList[0]
is a float. PriceList[0][1]
is trying to access the first element of a float. Instead, do
PriceList[0] = PriceList[1] = ...code omitted... = PriceList[6] = PizzaChange
或
PriceList[0:7] = [PizzaChange]*7
這篇關于TypeError:“浮動"對象不可下標的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!