"order_total" works fine in the function it was created in (take_customer_order) but for some reason I can't call it in the new function I made.
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
Here is where I added a new function to hopefully make order_total global:
def make_order_total_global():
take_customer_order.order_total()
return take_customer_order.order_total()
this was the original code I had submitted, the one having issues calling 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
And that's that. apparently since my edit is mostly code, I need more details now. Deets deeeties deeetily doooooo
CodePudding user response:
You cannot call the "take_customer_order.order_total ()" function because it has local visibility within the "take_customer_order ()" function and should have global visibility in order to be called. I recommend unpacking into two distinct functions in order to give global visibility to the "take_customer_order.order_total ()" function.
ex. from:
def hi ():
def hello ():
print ("hello")
hello ()
to:
def hello ():
print ("hello")
def hi ():
hello ()
Update:
Try this:
def make_order_total_global():
return take_customer_order()[0]
CodePudding user response:
Looks like take_customer_order
needs to return something...functions do not have attributes you can access outside of their scope.