Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 27 class VendingMachine(object):
- 26 """A vending machine that vends some product for some price.
- 25
- 24 >>> v = VendingMachine('crab', 10)
- 23 >>> v.vend()
- 22 'Machine is out of stock.'
- 21 >>> v.restock(2)
- 20 'Current crab stock: 2'
- 19 >>> v.vend()
- 18 'You must deposit $10 more.'
- 17 >>> v.deposit(7)
- 16 'Current balance: $7'
- 15 >>> v.vend()
- 14 'You must deposit $3 more.'
- 13 >>> v.deposit(5)
- 12 'Current balance: $12'
- 11 >>> v.vend()
- 10 'Here is your crab and $2 change.'
- 9 >>> v.deposit(10)
- 8 'Current balance: $10'
- 7 >>> v.vend()
- 6 'Here is your crab.'
- 5 >>> v.deposit(15)
- 4 'Machine is out of stock. Here is your $15.'
- 3 """
- 2 def __init__(self, __, _______):
- 1 self.__ = __
- 0 self._______ = _______
- 1 self.l__o_O__l = 0
- 2 self.____ = 0
- 3
- 4 def restock(self, count):
- 5 self.____ += count
- 6 return "Current {0} stock: {1}".format(self.__, self.____)
- 7
- 8 def deposit(self, ______):
- 9 if self.____ == 0:
- 10 return "Machine is out of stock. Here is your ${0}.".format(______)
- 11
- 12 self.l__o_O__l += ______
- 13 return "Current balance: ${0}".format(self.l__o_O__l)
- 14
- 15 def vend(self):
- 16 if self.____ == 0:
- 17 return "Machine is out of stock."
- 18
- 19 if self.l__o_O__l > self._______:
- 20 change = self.l__o_O__l - self._______
- 21 self.l__o_O__l = 0
- 22 self.____ -= 1
- 23 return "Here is your {0} and ${1} change.".format(self.__, change)
- 24 elif self.l__o_O__l == self._______:
- 25 self.l__o_O__l = 0
- 26 self.____ -= 1
- 27 return "Here is your {0}.".format(self.__)
- 28 else:
- 29 return "You must deposit ${0} more.".format(self._______-self.l__o_O__l)
Add Comment
Please, Sign In to add comment