Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
3.1 kB
3
Indexable
Never
MENU = {
    "espresso": {
        "ingredients": {
            "water": 50,
            "coffee": 18,
        },
        "cost": 1.5,
    },
    "latte": {
        "ingredients": {
            "water": 200,
            "milk": 150,
            "coffee": 24,
        },
        "cost": 2.5,
    },
    "cappuccino": {
        "ingredients": {
            "water": 250,
            "milk": 100,
            "coffee": 24,
        },
        "cost": 3.0,
    }
}

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



def current_profit():
    profit = 0

    return profit


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

    if resources['water'] > MENU[users_choice]['ingredients']['water'] or resources['milk'] > MENU[users_choice]['ingredients']['milk'] or resources['coffee'] > MENU[users_choice]['ingredients']['coffee']:
        return True
    else:
        return False



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: ${current_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 coffee_machine():


    users_choice = input("What would you like? (espresso/latte/cappuccino): ").lower()
    if users_choice in ['espresso', 'latte', 'cappuccino']:
        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:
            if check_if_enough_resources(users_choice) == True:
                change = round(count_change(inserted_amount, users_choice), 2)
                update_resources(users_choice)
                #current_profit() += MENU[users_choice]['cost']
                print(f"Here is ${change} in change.")
                print(f"Here is your {users_choice}. Enjoy!")
            else:
                print("Not enough resources, money refunded.")
        else:
            print("Sorry that's not enough money. Money refunded.")
        coffee_machine()
    elif users_choice == 'report':
        show_report()
        coffee_machine()
    elif users_choice == 'off':
        exit()


coffee_machine()