Guest User

Untitled

a guest
Jan 16th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. 27 class VendingMachine(object):
  2. 26 """A vending machine that vends some product for some price.
  3. 25
  4. 24 >>> v = VendingMachine('crab', 10)
  5. 23 >>> v.vend()
  6. 22 'Machine is out of stock.'
  7. 21 >>> v.restock(2)
  8. 20 'Current crab stock: 2'
  9. 19 >>> v.vend()
  10. 18 'You must deposit $10 more.'
  11. 17 >>> v.deposit(7)
  12. 16 'Current balance: $7'
  13. 15 >>> v.vend()
  14. 14 'You must deposit $3 more.'
  15. 13 >>> v.deposit(5)
  16. 12 'Current balance: $12'
  17. 11 >>> v.vend()
  18. 10 'Here is your crab and $2 change.'
  19. 9 >>> v.deposit(10)
  20. 8 'Current balance: $10'
  21. 7 >>> v.vend()
  22. 6 'Here is your crab.'
  23. 5 >>> v.deposit(15)
  24. 4 'Machine is out of stock. Here is your $15.'
  25. 3 """
  26. 2 def __init__(self, __, _______):
  27. 1 self.__ = __
  28. 0 self._______ = _______
  29. 1 self.l__o_O__l = 0
  30. 2 self.____ = 0
  31. 3
  32. 4 def restock(self, count):
  33. 5 self.____ += count
  34. 6 return "Current {0} stock: {1}".format(self.__, self.____)
  35. 7
  36. 8 def deposit(self, ______):
  37. 9 if self.____ == 0:
  38. 10 return "Machine is out of stock. Here is your ${0}.".format(______)
  39. 11
  40. 12 self.l__o_O__l += ______
  41. 13 return "Current balance: ${0}".format(self.l__o_O__l)
  42. 14
  43. 15 def vend(self):
  44. 16 if self.____ == 0:
  45. 17 return "Machine is out of stock."
  46. 18
  47. 19 if self.l__o_O__l > self._______:
  48. 20 change = self.l__o_O__l - self._______
  49. 21 self.l__o_O__l = 0
  50. 22 self.____ -= 1
  51. 23 return "Here is your {0} and ${1} change.".format(self.__, change)
  52. 24 elif self.l__o_O__l == self._______:
  53. 25 self.l__o_O__l = 0
  54. 26 self.____ -= 1
  55. 27 return "Here is your {0}.".format(self.__)
  56. 28 else:
  57. 29 return "You must deposit ${0} more.".format(self._______-self.l__o_O__l)
Add Comment
Please, Sign In to add comment