homeworkstudyhelp

Our Services

Get 15% Discount on your First Order

  PLEASEEE CREATE ILLUSTRATION OF EXACTLY HOW THE HIERARCHY CHART…

  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()
 

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Python –Gaussian Naive Bayes classifier How can I resolve this…

Python –Gaussian Naive Bayes classifier How can I resolve this Error “TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information “   CODE: from sklearn.datasets import load_svmlight_filefrom sklearn.model_selection import train_test_splitfrom sklearn.pipeline import make_pipelinefrom sklearn.preprocessing import StandardScalerfrom sklearn.naive_bayes import GaussianNB   # Load the data

Program should run in python 3     API :…

Program should run in python 3     API : https://api.chucknorris.io/   Outline : Welcome: Print a Welcome message for the user. : Make a GET request from the library to API: Chuck Norris Jokes. Choose science for as the category Only generate jokes of this categor  parse the JSON

ogram should run in python 3     API :…

ogram should run in python 3     API : https://api.chucknorris.io/   Outline : Welcome: Print a Welcome message for the user. : Make a GET request from the library to API: Chuck Norris Jokes. Choose science for as the category Only generate jokes of this categor parse the JSON

DTLearner import pandas as pd import numpy as np   class…

DTLearner import pandas as pd import numpy as np   class DTLearner(object):     def __init__(self, leaf_size = 1, verbose = False):         self.leaf_size = leaf_size         self.verbose = verbose         self.dataframe = None         self.tree = None

DTLearner import pandas as pd import numpy as np   class…

DTLearner import pandas as pd import numpy as np   class DTLearner(object):     def __init__(self, leaf_size = 1, verbose = False):         self.leaf_size = leaf_size         self.verbose = verbose         self.dataframe = None         self.tree = None

Two sum in Python: Based on array of different integers (ints) and…

Two sum in Python: Based on array of different integers (ints) and a single  integer (target), write function to print count/amount of combinations (non-repeating) of pairs of integers in (ints) such that the two integers sum to (target). Starting with: def twosum (ints, target): I’m not sure how to make

import pandas as pd import numpy as np from sklearn.model_selection…

import pandas as pdimport numpy as npfrom sklearn.model_selection import train_test_splitfrom sklearn import linear_modelfrom sklearn.metrics import r2_score import seaborn as snsimport matplotlib.pylab as plt%matplotlib inline   reg = linear_model.LinearRegression()X = iris[[‘petal_length’]]y = iris[‘petal_width’]reg.fit(X, y)print(“y = x *”, reg.coef_, “+”, reg.intercept_)   predicted = reg.predict(X)mse = ((np.array(y)-predicted)**2).sum()/len(y)r2 = r2_score(y, predicted)print(“MSE:”, mse)print(“R Squared:”,

how to calculate average maths score for student of each year…

how to calculate average maths score for student of each year level(9,10,11,12) at each school, using pandas. how to make a pandas series for each year, and group each series by school, and then combine the series in a dataframe the results like below   Year 9 Year 10 Year

def add(num1, num2):    return num1 + num2 def sub(num1, num2):…

def add(num1, num2):   return num1 + num2 def sub(num1, num2):   return num1 – num2 def mult(num1, num2):   return num1 * num2 def div(num1, num2):   if num2 == 0:       raise ZeroDivisionError(“Cannot divide by zero”)   else:       return num1 / num2 def isInRange(lr, hr, n):   if n >= lr

The Beauty of Data Visualization   Here is an easy and short…

The Beauty of Data Visualization   Here is an easy and short discussion post: watch this Ted Talk on data visualization. https://www.youtube.com/watch?v=5Zg-C8AAIGg   Watch the video, then answer the following questions: Summarize the video in a few sentences (2-4) Why is it important to visualize data in specific ways? Give

Since I used isdigit() method to verify the input, any floating…

Since I used isdigit() method to verify the input, any floating number input won’t be processed because of the “.” in the number. I suppose to use type conversion with “try, except” method instead.  # calculate pay(hours worked and hourly rate ) by declaring functiondef CalPay(hrs, rate):   if hrs <=

How to remove stopwords from. CSV to text classification or…

How to remove stopwords from. CSV to text classification or sentiment. my project is cyberbully detection using machine learning, and at the pre-processing stage, I need to remove some of the stopwords this error keeps showing up, and I can’t solve it ” TypeError: list indices must be integers or

A Python function definition is initiated by using this keyword in…

A Python function definition is initiated by using this keyword in the header:    function    def    import    It is necessary to include this punctuation at the end of a function header statement:    ; semi-colon    : colon    {opening curly brace    All statements within the

1 in contrast to a terminal-based program, a GUI-based program…

1 in contrast to a terminal-based program, a GUI-based program completely controls the order in which the user enters inputs can allow the user to enter inputs in any order   2 The attribute used to attach an event-handling method to a button is named pressevent onclick command