1 回答
![?](http://img1.sycdn.imooc.com/5458655200013d9802200220-100-100.jpg)
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
添加回答
举报