list.append()上的索引超出范围错误

时间:2019-05-13 00:46:31

标签: python

当我尝试从列表中选择一个项目并尝试对其进行追加时,它会返回错误IndexError:列表索引超出范围

def Choice_of_pizza():
      for i in range(1,pizza_no+1): #Repeats a number of times (number user has inputted)

      while True:
          try: #Validating inputs
              pizza_kind = int(raw_input("Choice of pizza(s):"))
              if pizza_kind < 1:
                  print("Refer to PIZZA MENU for pizza number")
                  continue
              if pizza_kind > 8:
                  print("Refer to PIZZA MENU for pizza number")
                  continue
              else:
                  pizza = pizza_kind - 1 #Makes the list start at 1
                  cost.append(pizzaPrice[pizza])
                  customerOrder.append(pizzaMenu[pizza])
                  global total_cost
                  total_cost = sum(cost) #Sum of the pizzas
                  global grandTotal
                  if delivery == "D": #Adds $5 dollars to the total cost if delivery
                      grandTotal = total_cost + deliveryCost
                  else: #Price stays the same if pick up 
                      grandTotal = total_cost
                      break
          except ValueError: #Validating inputs - accepts only numbers and can't be left blank 
              print("Please use numbers only")
              continue

Choice_of_pizza()

0 个答案:

没有答案