Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a VendingMachine object that performs the following operations: Purchases input number of drinks Restocks input number of bottles Reports inventory A VendingMachine's initial inventory is 20 drinks. Ex: If the input is: 5 2 the output is: Inventory: 17 bottles GIVEN: class VendingMachine: def __init__(self): self.bottles = 20 def purchase(self, amount): self.bottles = self.bottles - amount def restock(self, amount): self.bottles = self.bottles + amount def get_inventory(self): return self.bottles def report(self): print('Inventory: {} bottles'.format(self.bottles)) if __name__ == "__main__": # TODO: Create VendingMachine object # TODO: Purchase input number of drinks # TODO: Restock input number of bottles # TODO: Report inventory
7.13 LAB: Vending machine
Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a VendingMachine object that performs the following operations:
- Purchases input number of drinks
- Restocks input number of bottles
- Reports inventory
A VendingMachine's initial inventory is 20 drinks.
Ex: If the input is:
5 2the output is:
Inventory: 17 bottlesclass VendingMachine:
def __init__(self):
self.bottles = 20
def purchase(self, amount):
self.bottles = self.bottles - amount
def restock(self, amount):
self.bottles = self.bottles + amount
def get_inventory(self):
return self.bottles
def report(self):
print('Inventory: {} bottles'.format(self.bottles))
if __name__ == "__main__":
# TODO: Create VendingMachine object
# TODO: Purchase input number of drinks
# TODO: Restock input number of bottles
# TODO: Report inventory
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images