"order_total";在创建它的函数(take_customerorder)中运行良好,但由于某种原因,我无法在我创建的新函数中调用它。
def take_customer_order():
new_pizza = input("Order a pizza? (Y/N) ")
if new_pizza.upper() == "N":
return print("Have a nice day.")
if new_pizza.upper() != "Y" and new_pizza.upper() != "N":
return print("I'll take that as a no. Have a nice day.")
size, meats, veg, quantity = get_pizza_info(size=0, meats=0, veg=0, quantity=0)
if size == 1:
size_cost = 6.50
if size == 2:
size_cost = 9.50
if size == 3:
size_cost = 11.50
meats_cost = (meats - 1) * 3.50
veg_cost = (veg - 1) * 1.50
order_total = 0
pizza_total = (size_cost + meats_cost + veg_cost * quantity)
print("Pizza total: $", "{:,.2f}".format(pizza_total))
order_total += pizza_total
while new_pizza != "N":
new_pizza = input("Order a pizza? (Y/N) ")
if new_pizza.upper() == "N":
break
get_pizza_info(size, meats, veg, quantity)
print("Pizza total: $", "{:,.2f}".format(pizza_total))
order_total += pizza_total
print("Your total is $", "{:,.2f}".format(order_total))
return order_total, pizza_total
我在这里添加了一个新功能,希望能使order_total全局化:
def make_order_total_global():
take_customer_order.order_total()
return take_customer_order.order_total()
这是我提交的原始代码,调用order_total时出现问题。
def run_roccos_pizza_shop():
revenue = 0
patron_num = 0
while True:
partynum = input("Enter number in party or 'Close' to quit. ")
if partynum.upper() == "CLOSE":
print("Have a nice day!")
break
else:
patron_num += int(partynum)
revenue += take_customer_order.order_total()
print("Customers served: ", patron_num)
print("Total revenue $", "{:,.2f}".format(revenue))
return patron_num, revenue
就是这样。显然,由于我的编辑主要是代码,我现在需要更多的细节。Deets deeeties deeeties dooooo
您不能调用;take_customer_order.der_total()"函数,因为它在";take_customer_order()";函数,并且应该具有全局可见性才能被调用。我建议拆包成两个不同的功能,以便使";take_customer_order.der_total()"作用
前任。来自:
def hi ():
def hello ():
print ("hello")
hello ()
to:
def hello ():
print ("hello")
def hi ():
hello ()
更新:
试试这个:
def make_order_total_global():
return take_customer_order()[0]
看起来take_customer_order
需要返回一些东西。。。函数没有可以在其作用域之外访问的属性。