B
bcsoccer5
Guest
bcsoccer5 Asks: How can I call a function from a different class within another function of a separate class?
Currently I am working on a project and I am having issues calling a function from another class and I was wondering if anyone could help me.
'''
class MenuItem:
class LemonadeStand:
'''
My issue is within the total_profit_for_menu_item in the contribution margin variable. How can I get the wholesale cost and selling price for my menu item when the object is not the menu item itself, but contains the menu item?
Currently I am working on a project and I am having issues calling a function from another class and I was wondering if anyone could help me.
'''
class MenuItem:
Code:
def __init__(self, item: str, wholesale_cost: float, selling_price: float):
self._item = item
self._wholesale_cost = wholesale_cost
self._selling_price = selling_price
def get_name(self):
return self._item
def get_wholesale_cost(self):
return self._wholesale_cost
def get_selling_price(self):
return self._selling_price
class LemonadeStand:
Code:
def __init__(self, name: str):
self._name = name
self._current_day = 0
self._menu = {}
self._SalesForDay = []
def total_sales_for_menu_item(self, menu_item):
total = 0
for day in range(0, len(self._SalesForDay)):
total += self.sales_of_menu_item_for_day(day, menu_item)
return total
def total_profit_for_menu_item(self, menu_item):
total_sales = self.total_sales_for_menu_item(menu_item)
contribution_margin = (MenuItem.get_selling_price(menu_item) / MenuItem.get_wholesale_cost(menu_item)) / \
MenuItem.get_selling_price(menu_item)
total_profit = total_sales * contribution_margin
return total_profit
'''
My issue is within the total_profit_for_menu_item in the contribution margin variable. How can I get the wholesale cost and selling price for my menu item when the object is not the menu item itself, but contains the menu item?
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.