Search code examples
pythonlistreplaceinsertindexing

TypeError: 'float' object is not subscriptable


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?


Solution

  • 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
    

    or

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