title: Obj orientation programming - accessing names from another class
body: <p>Methods:</p>
  
  <p>– Constructor takes in no argument.</p>
  
  <p>– get_stock_names(): returns a list of strings that represents the names of
  all food items in the stock.</p>
  
  <p>– has_stock(name): returns True if a food item’s name is found in stock.</p>
  
  <p>– load(food): add the food object to stock.</p>
  
  <p>– sell(name): returns the item to be sold. The item to be sold is the first
  food item in the stock list that matches the input name. Remember to
  remove the sold food item from stock. If the item name does not match any
  in the list, return None.</p>
  
  <pre><code>class Food(object):
      def __init__(self,name,nutrition,good_until):
          self.name = name
          self.nutrition = nutrition
          self.good_until = good_until
          self.age = 0
  
  class FermentedFood(Food):
      def __init__(self,name,nutrition,good_after,good_until):
          super().__init__(name,nutrition,good_until)
          self.good_after = good_after
  </code></pre>
  
  <p>These are previously defined</p>
  
  <pre><code>class VendingMachine(object):
      def __init__(self):
          self.obj = []
      def load(self,food):
          self.obj.append(food)
          return self.obj
      def get_stock_names(self):
          return [i.name for i in self.obj]
      def has_stock(self,name):  # This part is wrong
          return  str(name) == self.obj
      def sell(self,name): # This part is wrong as well 
          if str(self.name) == self.obj:
              self.obj.remove(self.name)
          else:
              return None    
  
  
  machine = VendingMachine()
  apple = Food("apple", 70, 7)
  banana = Food("banana", 100, 4)
  yoghurt = FermentedFood("yoghurt", 50, 0, 10)
  machine.load(banana)
  machine.load(apple)
  machine.load(yoghurt)
  machine.load(apple)
  print(machine.get_stock_names())  #["banana", "apple", "yoghurt", "apple"])
  print(machine.has_stock("apple"))
  print(machine.sell("apple")) #True
  print(machine.get_stock_names()) ##Since apple is sold so `["banana", "yoghurt", "apple"]`
  </code></pre>
  
  <p>So what is wrong with <code>has_stock</code> and <code>sell</code>  ?</p>