class CoffeeMachine: def __init__(self): self.on = True self.menu = Menu() self.coffee_maker = CoffeeMaker() self.money_machine = MoneyMachine() def start(self): while self.on: print("Welcome to your coffee machine!\n") request = input( f"\nWhat would you like? ({self.menu.get_items()}):").lower() if request == "off": self.on = False print("Bye bye!") elif request == "report": self.coffee_maker.report() self.money_machine.report() else: order = self.menu.find_drink(request) if order: sufficient_resources = self.coffee_maker.is_resource_sufficient( order) if sufficient_resources: cost = order.cost print( f"\nIt will be {self.money_machine.CURRENCY}{cost}" ) if self.money_machine.make_payment(cost): self.coffee_maker.make_coffee(order)
def run_coffee_machine(): menu = Menu() # menu_item = MenuItem() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() def input_response(): """Returns the user response for the choice of drink""" resp = input(f"What would you like? {menu.get_items()}: ") if resp not in ['espresso', 'latte', 'cappuccino', 'report', 'off']: resp = input(f"What would you like? {menu.get_items()}: ") return resp def handle_drink(a_drink): """Gets the money made from each transaction and updates the resources """ if coffee_maker.is_resource_sufficient( a_drink) and money_machine.make_payment(a_drink.cost): coffee_maker.make_coffee(a_drink) # start of the routine response = input_response() while response: if response == 'off': return elif response == 'report': coffee_maker.report() response = input_response() else: drink = menu.find_drink(response) handle_drink(drink) response = input_response()
class CoffeeMachine: def __init__(self): self.money_machine = MoneyMachine() self.coffee_maker = CoffeeMaker() self.menu = Menu() def run(self): is_on = True while is_on: options = self.menu.get_items() choice = input(f"What would you like? ({options}): ").lower() if choice == "off": is_on = False elif choice == "report": self.coffee_maker.report() self.money_machine.report() else: drink = self.menu.find_drink(choice) if drink != "None": is_enough_ingredients = self.coffee_maker.is_resource_sufficient( drink) is_payment_successful = False if is_enough_ingredients: is_payment_successful = self.money_machine.make_payment( drink.cost) if is_payment_successful: self.coffee_maker.make_coffee(drink)
def drink_machine(): cm = CoffeeMaker() mm = MoneyMachine() m = Menu() while True: drink = request(cm, mm, m) if cm.is_resource_sufficient(drink): if mm.make_payment(drink.cost): cm.make_coffee(drink)
def coffee_machine(): should_run_machine = True while should_run_machine: myMenu = Menu() choice = input(f"What would you like to have? {myMenu.get_items()}: ") myMenuItem = myMenu.find_drink(order_name=choice) if myMenuItem == None: should_run_machine = False else: maker = CoffeeMaker() if maker.is_resource_sufficient: myMoneyMachine = MoneyMachine() if myMoneyMachine.make_payment(myMenuItem.cost): maker.make_coffee(myMenuItem) print(maker.report())
class CoffeeMachine: def __init__(self): self.coffee_maker = CoffeeMaker(water=300, milk=200, coffee=100) self.cash_registry = CashRegistry() self.menu = Menu() self.running = False def get_report(self): report = self.coffee_maker.get_report() report.update(self.cash_registry.get_report()) message = "" for element, quantity in report.items(): measure = "ml" if element == "Coffee": measure = "g" if element == "Money": measure = "$" message += "{}: {}{}".format(element, measure, quantity) else: message += "{}: {}{}\n".format(element, quantity, measure) return message def start(self): self.running = True while self.running: choice = input( "What would you like? (espresso/latte/cappuccino): ").strip() if choice == "off": self.running = False elif choice == "report": print(self.get_report()) elif choice == "restock": self.coffee_maker.restock(300, 200, 30) elif choice in self.menu.get_items(): price = self.menu.get_price(choice) print("{} costs ${}".format(choice.capitalize(), price)) success, change = self.cash_registry.parse_transaction( cost=price) if success: ingredients = self.menu.get_ingredients(choice) message = self.coffee_maker.make(choice, ingredients) else: message = "Sorry, that's not enough money. Money refunded." if change: message += "\nHere is ${} in change.".format(change) print(message) else: print("We don't serve this type of coffee.")
def start(menu=Menu(), coffee_maker=CoffeeMaker(), money_machine=MoneyMachine()): # TODO 1: Prompt user asking what would you like? answer_list = ["espresso", "latte", "cappuccino", "off", "report"] answer = input(f"What would you like? ({menu.get_items()}): ").lower() while answer not in answer_list: print("Wrong answer. Please type again.") answer = input(f"What would you like? ({menu.get_items()}): ").lower() # TODO 2: Turn off the coffee machine by entering off to the prompt if answer == "off": print("Turning off the coffee machine. Good bye.") return # TODO 3: Print Report elif answer == "report": coffee_maker.report() money_machine.report() # TODO 4: Check resources suficient elif menu.find_drink(answer) is not None: item = menu.find_drink(answer) if coffee_maker.is_resource_sufficient(item): # TODO 5: Process coins payment_successfully = money_machine.make_payment(item.cost) # TODO 6: Check transaction successfull? if payment_successfully: # TODO 7: Make coffee coffee_maker.make_coffee(item) # Restart start(menu, coffee_maker, money_machine)
def check_resources(user_order): global new_menu money_machine = MoneyMachine() coffee_maker = CoffeeMaker() if user_order == 'report': new_report = CoffeeMaker() return new_report.report() elif user_order == 'off': is_on = False return is_on else: new_drink = new_menu.find_drink(user_order) coffee_machine = CoffeeMaker() if coffee_machine.is_resource_sufficient( new_drink) and money_machine.make_payment(new_drink.cost): coffee_maker.make_coffee(user_order)
def coffee_machine(): my_coffee_machine = CoffeeMaker() my_money_machine = MoneyMachine() my_menu = Menu() machine_off = False while not machine_off: options = my_menu.get_items() choice = input(f"Which drink would you like ({options}) ? \n > ") if choice == 'report': my_coffee_machine.report() my_money_machine.report() elif choice == 'off': machine_off = True else: selected_drink = my_menu.find_drink(choice) if selected_drink is not None: # Check if sufficient resources is_resource_sufficient = my_coffee_machine.is_resource_sufficient( selected_drink) if is_resource_sufficient: # Take payment is_paid_amount_sufficient = False while not is_paid_amount_sufficient: is_paid_amount_sufficient = my_money_machine.make_payment( selected_drink.cost) # Once enough money provided, and transaction registered, make coffee my_coffee_machine.make_coffee(selected_drink)
def main(): # This is the menu menu = Menu() cm = CoffeeMaker() mm = MoneyMachine() while True: drinks = menu.get_items() choice = input(f"What drink would you like? We serve {drinks} ") if choice == "off": print("Coffee machine turning off...") return elif choice == "report": cm.report() mm.report() continue else: # Check user selected a valid drink drink = menu.find_drink(choice) if drink == 'e': # error catcher continue if cm.is_resource_sufficient(drink): if mm.make_payment(drink.cost): cm.make_coffee(drink) else: continue else: continue
def main(): is_on = True menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() while is_on: choice = input(f"What would you like? ({menu.get_items()}): ") if choice == "report": coffee_maker.report() money_machine.report() elif choice == "off": is_on = False else: # search for the drink drink = menu.find_drink(choice) # make sure its exists if drink: # make sure we have the resources if coffee_maker.is_resource_sufficient(drink): # and that we got enough money if money_machine.make_payment(drink.cost): # do it! coffee_maker.make_coffee(drink)
def run_machine(): menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() while True: # TODO: Prompt user by asking “What would you like? (espresso/latte/cappuccino):” order = input(f"What would you like? ({menu.get_items()}): ") # TODO: Turn off the Coffee Machine by entering “off” to the prompt. if order == 'off': break # TODO: Print report elif order == 'report': coffee_maker.report() money_machine.report() else: validated_order = menu.find_drink(order) # TODO: Check resources sufficient is_enough_ingredients = coffee_maker.is_resource_sufficient( validated_order) # TODO: Process Coins is_payment_successful = money_machine.make_payment( validated_order.cost) # TODO: Check transaction successful if is_enough_ingredients and is_payment_successful: coffee_maker.make_coffee(validated_order)
def main(): menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() is_cm_running = True while is_cm_running: # ask for user Input is_input_invalid = True while is_input_invalid: user_action = input("What would you like? (espresso/latte/cappuccino): ").lower() if user_action == "espresso" or \ user_action == "latte" or \ user_action == "cappuccino" or \ user_action == "report" or \ user_action == "off": is_input_invalid = False else: print("Invalid input!") if user_action == "off": is_cm_running = False continue elif user_action == "report": coffee_maker.report() money_machine.report() else: coffee = menu.find_drink(user_action) if coffee_maker.is_resource_sufficient(coffee) and \ money_machine.make_payment(coffee.cost): coffee_maker.make_coffee(coffee)
def user_interaction(): # creating the coffee maker, the menu and the money machine my_coffee_maker = CoffeeMaker() my_menu = Menu() my_money_machine = MoneyMachine() currently_attending = True while currently_attending: chosen_coffee_type = input(f"What would you like? ({my_menu.get_items()}) ").lower() if chosen_coffee_type == "report": # creating the report my_coffee_maker.report() my_money_machine.report() elif chosen_coffee_type == "off": currently_attending = False else: my_menu_item = my_menu.find_drink(chosen_coffee_type) if my_coffee_maker.is_resource_sufficient(my_menu_item): # proceeding to coin processing as sufficient resources if my_money_machine.make_payment(my_menu_item.cost): # coffee can be made now my_coffee_maker.make_coffee(my_menu_item)
def coffee_machine(): """Starts the coffee machine and makes it run""" # Creates a new CoffeeMaker object coffee_maker = CoffeeMaker() # Creates a new MoneyMachine object money_machine = MoneyMachine() # Creates a new Menu object menu = Menu() # Initializes the variable indicating if the machine goes off off = False # As long as the machine is not off, it runs while not off: # Displays the machine's menu to the user and stores his choice user_choice = input( f"What would you like? ({menu.get_items()}): ").lower() # Checks the user's choice if user_choice == "off": # The user is a technician and turned off the machine using the choice "off" # The variable off becomes True which will stop the machine off = True elif user_choice == "report": # The user asked for a report of the machine's resources using the choice "report" # Prints the coffee maker report coffee_maker.report() # Prints the money machine report money_machine.report() else: # Looks for the user's choice in the menu drink = menu.find_drink(user_choice) # Checks if the user selected an existing drink if drink != "None": # The user asked for a drink among the menu # Checks if the machine has sufficient resources to make the drink if coffee_maker.is_resource_sufficient(drink): # The machine has sufficient resources # Asks the user to insert coins and checks if the user inserted enough to pay the drink money_machine.make_payment(drink.cost) # Deducts ingredients of the drink from the machine's resources coffee_maker.make_coffee(drink) else: # The user made an invalid choice # Prints the user he made an invalid choice print("Invalid choice")
def play(): again = True menu = Menu() coffe = CoffeeMaker() money = MoneyMachine() while again: order_name = input(f"What would you like? {menu.get_items()}: ") if order_name == "off": again = False elif order_name == "report": coffe.report() money.report() else: order = menu.find_drink(order_name) if coffe.is_resource_sufficient(order): if money.make_payment(order.cost): coffe.make_coffee(order)
def order_coffee(): menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() is_on = True while is_on: user_input = input(f"What would you like? {menu.get_items()}:") if user_input == 'off': is_on = False elif user_input == 'report': coffee_maker.report() money_machine.report() else: drink = menu.find_drink(user_input) if drink and coffee_maker.is_resource_sufficient( drink) and money_machine.make_payment(drink.cost): coffee_maker.make_coffee(drink)
def coffee_machine(): menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() while True: options = menu.get_items() choice = input(f'What would you like? ({options}): ').lower() if choice == 'off': return elif choice == 'report': coffee_maker.report() money_machine.report() else: coffee = menu.find_drink(choice) if coffee_maker.is_resource_sufficient(coffee): if money_machine.make_payment(coffee.cost): coffee_maker.make_coffee(coffee)
def main(): cm = CoffeeMaker() mm = MoneyMachine() menu = Menu() is_on = True while is_on: print() choice = input("What would you like? (%s): " % menu.get_items()) if choice == 'report': cm.report() mm.report() elif choice == 'off': is_on = False else: drink = menu.find_drink(choice) if drink and cm.is_resource_sufficient(drink): if mm.make_payment(drink.cost): cm.make_coffee(drink)
def coffee_machine(): my_menu = Menu() my_coffee_maker = CoffeeMaker() my_money_machine = MoneyMachine() machine_on = True while machine_on: order = input(f'What would you like? ({my_menu.get_items()}) ') if order == 'off': print('Shutting down. Good bye.') machine_on = False elif order == 'report': my_coffee_maker.report() my_money_machine.report() else: drink = my_menu.find_drink(order) if drink is not None and \ my_coffee_maker.is_resource_sufficient(drink) and \ my_money_machine.make_payment(drink.cost): my_coffee_maker.make_coffee(drink)
def main(): is_on = True menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() while is_on: selection = menu.display() ##print(coffee_maker.is_resource_sufficient('cappuccino')) if selection == 'off': print("Turning OFF the machine") is_on = False elif selection == 'report': coffee_maker.report() money_machine.report() else: options = menu.get_items(selection) if coffee_maker.is_resource_sufficient(options): money_machine.collect_coins(selection, options.cost) coffee_maker.make_coffee(options)
def coffee_machine(): print('Welcome to coffee machine ☕') coffee_maker = CoffeeMaker() money_machine = MoneyMachine() menu = Menu() options = menu.get_items() user_input = input(f'What would you like? ({options}): ') if user_input == 'report': coffee_maker.report() money_machine.report() return coffee_machine() elif user_input == 'off': print('Bye than') return else: drink = menu.find_drink(user_input) if coffee_maker.is_resource_sufficient(drink) and money_machine.make_payment(drink.cost): coffee_maker.make_coffee(drink) another_coffee = input('Would you like to have another coffee? "yes" or "no": ') if another_coffee == 'yes': return coffee_machine()
from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine coffee_maker = CoffeeMaker() money_machine = MoneyMachine() menu = Menu() is_on = True while is_on: options = menu.get_items() choice = input(f"What would you like? ({options}): ") if choice == "off": is_on = False elif choice == "report": coffee_maker.report() money_machine.report() else: drink = menu.find_drink(choice) if coffee_maker.is_resource_sufficient(drink) and money_machine.make_payment(drink.cost): coffee_maker.make_coffee(drink)
from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine my_money_machine = MoneyMachine() my_coffee_machine = CoffeeMaker() my_menu = Menu() machine_on = True while machine_on: options = my_menu.get_items() customer_order = input(f"What would you like? ({options}) ") if customer_order == "off": print("Turning off.") machine_on = False elif customer_order == "report": my_coffee_machine.report() my_money_machine.report() else: drink = my_menu.find_drink(customer_order) if my_coffee_machine.is_resource_sufficient( drink) and my_money_machine.make_payment(drink.cost): my_coffee_machine.make_coffee(drink)
from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine menu=Menu() maker=CoffeeMaker() money=MoneyMachine() def coffeemachineMK2(): while True: choice=input(f"What do you want? {menu.get_items()} :").lower() if choice=="report": print(maker.report()) print(money.report()) continue elif choice=="off": print(f"The machine is off\n{money.report()}") return 0 drink=menu.find_drink(choice) if maker.is_resource_sufficient(drink) and money.make_payment(drink.cost): maker.make_coffee(drink) coffeemachineMK2()
from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine from replit import clear machine = CoffeeMaker() wallet = MoneyMachine() menu = Menu() machine_on = True while machine_on: clear() option = input( 'What do you want to do?\n(1) - Buy a coffee\n(2) - Print Report\n(3) - Turn off machine\n You option is: ' ) if option == '1': clear() coffee_option = input( 'What coffee do you want?\n(1) - Espresso\n(2) - Latte\n(3) - Cappuccino\n You option is: ' ) if coffee_option == '1': coffee = 'espresso' elif coffee_option == '2': coffee = 'latte' elif coffee_option == '3': coffee = 'cappuccino' if machine.is_resource_sufficient(menu.find_drink(coffee)): if wallet.make_payment(menu.find_drink(coffee).cost): machine.make_coffee(menu.find_drink(coffee)) else:
from menu import Menu # , MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine menu = Menu() cofee_maker = CoffeeMaker() money_machine = MoneyMachine() item_list = menu.get_items().split("/") # remove empty items while "" in item_list: item_list.remove("") menu_options = ["report", "off"] menu_options.extend(item_list) machine_is_on = True while machine_is_on: choice = input(f"What would you like? ({'/'.join(item_list)}): ").lower() if choice == "off": machine_is_on = False elif choice == "report": cofee_maker.report() money_machine.report() elif choice in item_list: drink = menu.find_drink(choice) if cofee_maker.is_resource_sufficient(drink): if money_machine.make_payment(drink.cost): cofee_maker.make_coffee(drink) money_machine.money_received = 0
from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine menu = Menu() coffee_maker = CoffeeMaker() money_machine = MoneyMachine() while True: coffee_type = input(f'Please pick your coffee {menu.get_items()} ') if coffee_type == 'report': coffee_maker.report() money_machine.report() continue coffee_object = menu.find_drink(coffee_type) if coffee_object: if coffee_maker.is_resource_sufficient(coffee_object): charge = coffee_object.cost print(f"That'll be ${float(coffee_object.cost)}. ") if money_machine.make_payment(charge): coffee_maker.make_coffee(coffee_object) else: continue
from menu import Menu from coffee_maker import CoffeeMaker from money_machine import MoneyMachine CoffeMakerObj = CoffeeMaker() MoneyMachineObj = MoneyMachine() MenuObj = Menu() while True: cmd = input(f"What would you like? ({MenuObj.get_items()}) [or 'report']: ").lower() if cmd == 'off': print("Goodbye!") break if cmd == 'report': CoffeMakerObj.report() MoneyMachineObj.report() else: drink = MenuObj.find_drink(cmd) if not drink: continue if not CoffeMakerObj.is_resource_sufficient(drink): continue if not MoneyMachineObj.make_payment(drink.cost): continue CoffeMakerObj.make_coffee(drink)
from menu import Menu from coffee_maker import CoffeeMaker from money_machine import MoneyMachine money_machine = MoneyMachine() coffee_maker = CoffeeMaker() menu = Menu() is_on = True while is_on: options = menu.get_items() choice = input(f"What would you like? ({options}): ") if choice == "off": is_on = False elif choice == "report": coffee_maker.report() money_machine.report() else: drink = menu.find_drink(choice) # print(drink) is_enough_ingredients = coffee_maker.is_resource_sufficient(drink) is_payment_successful = money_machine.make_payment(drink.cost) if is_enough_ingredients and is_payment_successful: coffee_maker.make_coffee(drink)