Untitled

 avatar
unknown
python
2 years ago
3.6 kB
6
Indexable
MENU = {
    "espresso": {
        "ingredients": {
            "water": 50,
            "coffee": 18,
        },
        "cost": 1.5,
    },
    "latte": {
        "ingredients": {
            "water": 200,
            "milk": 150,
            "coffee": 324,
        },
        "cost": 2.5,
    },
    "cappuccino": {
        "ingredients": {
            "water": 250,
            "milk": 100,
            "coffee": 24,
        },
        "cost": 3.0,
    }
}

resources = {
    "water": 300,
    "milk": 200,
    "coffee": 100,
    "profit": 0,
}



def check_if_enough_money(choice, inserted_amount):

    coffee_cost = MENU[choice]['cost']
    if inserted_amount == coffee_cost or inserted_amount > coffee_cost:
        return True
    else:
        return False


def check_if_enough_resources(choice):

    for key, value in MENU[choice]['ingredients'].items():
        # print(f"Key: {key}, value: {value}")
        # print(f"Resources: {resources[key]}")
        if value > resources[key]:
            #print(f'Not enough {key}.')
            return key

    return True

    # for key, value in MENU[choice]['ingredients'].items():
    #     # print(f"Key: {key}, value: {value}")
    #     # print(f"Resources: {resources[key]}")
    #     if resources[key] < value:
    #         #print(f'Not enough {key}.')
    #         return key
    #
    # return True


def count_change(inserted_amount, users_choice):
    change = inserted_amount - MENU[users_choice]['cost']
    return change


def show_report():
    print(f"Water: {resources['water']}ml\n"
          f"Milk: {resources['milk']}ml\n"
          f"Coffee: {resources['coffee']}g\n"
          f"Money: ${resources['profit']}"
          )


def update_resources(users_choice):

    resources['water'] = resources['water'] - MENU[users_choice]['ingredients']['water']
    resources['coffee'] = resources['coffee'] - MENU[users_choice]['ingredients']['coffee']
    if users_choice != 'espresso':
        resources['milk'] = resources['milk'] - MENU[users_choice]['ingredients']['milk']

    return


def update_profit(users_choice):

    resources['profit'] += MENU[users_choice]['cost']

    return


def coffee_machine():


    users_choice = input("What would you like? (espresso/latte/cappuccino): ").lower()
    if users_choice in ['espresso', 'latte', 'cappuccino']:

        if check_if_enough_resources(users_choice) == True:
            print("Please insert coins.")
            quarters = int(input("How many quarters?: "))
            dimes = int(input("How many dimes?: "))
            nickel = int(input("How many nickels?: "))
            pennies = int(input("How many pennies?: "))
            inserted_amount = quarters * 0.25 + dimes * 0.1 + nickel * 0.05 + pennies * 0.01
            is_enough = check_if_enough_money(users_choice, inserted_amount)

            if is_enough == True:
                change = round(count_change(inserted_amount, users_choice), 2)
                update_resources(users_choice)
                update_profit(users_choice)
                print(f"Here is ${change} in change.")
                print(f"Here is your {users_choice}. Enjoy!")
                coffee_machine()
            else:
                print("Sorry that's not enough money. Money refunded.")
                coffee_machine()
        else:
            print(f"Sorry not enough {check_if_enough_resources(users_choice)}.")
            coffee_machine()


    elif users_choice == 'report':
        show_report()
        coffee_machine()

    elif users_choice == 'off':
        exit()


coffee_machine()
Editor is loading...