MacSG

LabComPro-Mid_6

Mar 29th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. class IceCream :
  2.    
  3.     def __init__(self, type, num):
  4.         self.type = type
  5.         self.num = num
  6.         self.flavors = []
  7.        
  8.     def add(self, flavor):
  9.         if len(self.flavors) < self.num :
  10.             self.flavors.append(flavor)
  11.         else :
  12.             pass
  13.        
  14.     def have(self,flavor):
  15.         return self.flavors.count(flavor)
  16.  
  17. #Main Program
  18. ic = IceCream('Cone',3)
  19. ic.add('Strawberry')
  20. ic.add('Chocolate')
  21. ic.add('Strawberry')
  22. ic.add('Vanilla')
  23. print(ic.have('Strawberry'))
  24. print(ic.have('Vanilla'))
Advertisement
Add Comment
Please, Sign In to add comment