fork download
  1. class Customer:
  2. """
  3. Tracks the customers data (orders, table number, name, total payments,
  4. ordered food, turn in the queue, served or not, and if he left or not),
  5. you can get all the required data using 'customer_x.info['attribute']'
  6. you can also add to his order using 'new_order()', serve him using 'serve()'
  7. and sign him off using 'leave()'.
  8. *Note: the customer might sign in and order later
  9. """
  10.  
  11. _active_customers={}
  12. _all_customers={}
  13. customer_counter=1
  14.  
  15. def __init__(self, name:str, table:int, *argu, order_code:None|int=None, turn_in_queue:None|int=None):
  16. self.name=name
  17. self.table=table
  18. self.ordered_food=list(argu)
  19. self.order_code=order_code
  20. self._total_cost=0 # protected so it can't be changed
  21. self.turn_in_queue=turn_in_queue
  22. self._served=False # protected so it's only true when the customer is served
  23. self.present=True # checks if the customer left or still have the table
  24. self.customer_id=f"{name}, id:{Customer.customer_counter}"
  25. # to-do: make table taken
  26. Customer._active_customers[self.id]=self
  27. Customer._all_customers[self.id]=self
  28. Customer.customer_counter+=1
  29.  
  30. @classmethod
  31. def active_customers(cls):
  32. return Customer._active_customers.keys()
  33.  
  34. @classmethod
  35. def all_customers(cls):
  36. return Customer._all_customers.keys()
  37.  
  38. @property
  39. def is_served(self):
  40. return self._served
  41.  
  42. @property
  43. def total_cost(self): #calculates the total payments by suming each meal cost
  44. # to-do: calculate the cost of each meal
  45. return self._total_cost
  46.  
  47. @property
  48. def info(self):
  49. return {
  50. "name": self.name,
  51. "table": self.table,
  52. "ordered_food": self.ordered_food,
  53. "order_code": self.order_code,
  54. "turn_in_queue": self.turn_in_queue,
  55. "served": self._served,
  56. "present": self.present
  57. }
  58.  
  59. def serve(self):
  60. if self.is_served: print(f"Customer {self.name} doesn't need serves!"); return
  61. self._served=True
  62. self.order_code=None
  63. self.turn_in_queue=None
  64. print(f"Customer {self.name} was served!")
  65.  
  66. def leave(self): # signs off customers and make the table empty
  67. # to-do: make the table empty
  68. self.present=False
  69. del Customer._active_customers[self.id]
  70. print(f"Customer {self.name} left!")
  71.  
  72. def new_order(self, order_code:int, turn_in_queue:int, *argu):
  73. self.order_code=order_code
  74. self.ordered_food.extend(argu)
  75. self.turn_in_queue=turn_in_queue
  76. self._served=False
  77. print(f"Customer {self.name} ordered the next: \n{'\n'.join(str(item) for item in argu)}") # to-do: make order table with price of each meal
  78.  
  79. """
  80. notes: search for 'to-do:' part
  81. in the code and customise it based
  82. on your part
  83. """
  84.  
  85. """
  86. plans: add online/offline orders
  87. add number of customers on the table
  88. """
Success #stdin #stdout 0.08s 14052KB
stdin
Standard input is empty
stdout
Standard output is empty