1 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
代碼問(wèn)題:
對(duì)于加法賦值,語(yǔ)法為:
x += y # 將 x 分配給 (x + y)
不是:
x?=?+y??#?this?assign?x?to?y
Glbol 不會(huì)在您的代碼中造成問(wèn)題,但通常會(huì)令人不悅并對(duì)編程技能產(chǎn)生負(fù)面影響,即為什么全局變量是邪惡的?。
Choice_of_pizza功能修復(fù)
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
添加回答
舉報(bào)