1 回答

TA貢獻1784條經驗 獲得超7個贊
代碼問題:
對于加法賦值,語法為:
x += y # 將 x 分配給 (x + y)
不是:
x?=?+y??#?this?assign?x?to?y
Glbol 不會在您的代碼中造成問題,但通常會令人不悅并對編程技能產生負面影響,即為什么全局變量是邪惡的?。
Choice_of_pizza功能修復
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(input("Choice of pizza(s):"))
? ? ? ? ? if pizza_kind < 1:
? ? ? ? ? ? print("Refer to PIZZA MENU for number order")
? ? ? ? ? ? continue
? ? ? ? ? if pizza_kind > 12:
? ? ? ? ? ? print("Refer to PIZZA MENU for number order")
? ? ? ? ? ? continue
? ? ? ? ? else:
? ? ? ? ? ? pizza = pizza_kind - 1 #Makes the list start at 1
? ? ? ? ? ? print('\nYou have chosen {}\n'.format(MENU[pizza_kind-1][0]))
? ? ? ? ? ? customerOrder.append(MENU[pizza_kind-1])
? ? ? ? ? ? cost = 0
? ? ? ? ? ? for i in range(len(customerOrder)):
? ? ? ? ? ? ? cost += customerOrder[i][1]
? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? global total_cost? # globals are discouraged
? ? ? ? ? ? total_cost=0
? ? ? ? ? ? #Sum of the pizzas
? ? ? ? ? ? global Combined_Total # globals are discouraged
? ? ? ? ? ? if delivery == "D": #Adds $3 dollars to the total cost if delivery
? ? ? ? ? ? ? total_cost += cost
? ? ? ? ? ? ? Combined_Total = total_cost + Delivery_cost
? ? ? ? ? ? else: #Price stays the same if pick up
? ? ? ? ? ? ? total_cost += cost
? ? ? ? ? ? ? Combined_Total = total_cost
? ? ? ? ? ? break
? ? ? ? except ValueError:#Validating inputs - accepts only numbers and can't be left blank?
? ? ? ? ? print("Please use numbers only")
? ? ? ? ? continue
添加回答
舉報