PLEASEEE CREATE ILLUSTRATION OF EXACTLY HOW THE HIERARCHY CHART WILL LOOK USING THE CODE BELOW.
THE CODE MUST BE HORIZONTAL. USE THIS PHOTO AS AN EXAMPLE OF WHAT IT IS SUPPOSED TO LOOK LIKE !!!
class VendingMachine:
def __init__(self):
self.products = {
‘A’: {‘name’: ‘Soda’, ‘price’: 1.50, ‘quantity’: 10},
‘B’: {‘name’: ‘Chips’, ‘price’: 1.00, ‘quantity’: 15},
‘C’: {‘name’: ‘Chocolate’, ‘price’: 2.00, ‘quantity’: 8},
‘D’: {‘name’: ‘Candy Bar’, ‘price’: 1.25, ‘quantity’: 12},
‘E’: {‘name’: ‘Water’, ‘price’: 1.00, ‘quantity’: 20},
‘F’: {‘name’: ‘Gum’, ‘price’: 0.75, ‘quantity’: 25}
}
self.balance = 0.0
def display_products(self):
print(“Available Products:”)
for code, product in self.products.items():
print(f”{code}. {product[‘name’]} – ${product[‘price’]:.2f} ({product[‘quantity’]} left)”)
def select_product(self, code):
return self.products.get(code)
def accept_payment(self, selected_product):
while True:
try:
payment = float(input(f”Insert ${selected_product[‘price’]:.2f}: “))
if payment >= selected_product[‘price’]:
return payment
else:
print(“Insufficient payment. Please insert more money.”)
except ValueError:
print(“Invalid input. Please enter a valid amount.”)
def dispense_product(self, selected_product):
print(f”Dispensing {selected_product[‘name’]}…”)
selected_product[‘quantity’] -= 1
def make_change(self, payment, selected_product):
change = payment – selected_product[‘price’]
self.balance += selected_product[‘price’]
if change > 0:
print(f”Change: ${change:.2f}”)
def check_restock(self):
“””Check product quantities and restock if needed.”””
for code, product in self.products.items():
if product[‘quantity’] <= 2: # Set your desired threshold for restocking
print(f”Warning: {product[‘name’]} is low on stock. Restocking…”)
# Simulate restocking by resetting the quantity back to the original count
product[‘quantity’] = 10
print(f”{product[‘name’]} has been restocked to the original quantity.”)
def run(self):
while True:
self.display_products()
self.check_restock() # Check for restocking before accepting user input
code = input(“Enter the product code (A-F) or ‘q’ to quit: “).upper()
if code == ‘Q’:
print(“Exiting. Thank you!”)
break
selected_product = self.select_product(code)
if selected_product:
payment = self.accept_payment(selected_product)
if payment >= selected_product[‘price’]:
self.dispense_product(selected_product)
self.make_change(payment, selected_product)
print(f”Enjoy your {selected_product[‘name’]}!”)
else:
print(“Transaction canceled. Returning payment.”)
else:
print(“Invalid product code. Please try again.”)
if __name__ == “__main__”:
vending_machine = VendingMachine()
vending_machine.run()