본문 바로가기

Python 🎧

[python] 커피머신 - while/list/array/def

진심 쉽게만 살아가고 싶다 ...

내가 듣는 파이썬 강의 쉽게 따라가기 좋다

 

☕️ 강의 

https://www.udemy.com/course/100-days-of-code/

 

☕️ main.py

import menu

def resource_suff(order) :
    """재료 충분한지 췤!"""
    for item in order :
        if order[item] >= menu.resources[item] :
            print(f"미앙 {item} (이)가 없슴다 ")
            return False
    return True

def process_coin() :
    """총 금액 췤!"""
    print("동전을 투입하시오 : ")
    total = int(input("쿼터 몇개 ? :")) * 0.25
    total += int(input("다임 몇개 ? :")) * 0.1
    total += int(input("니켈 몇개 ? :")) * 0.05
    total += int(input("페니 몇개 ? :")) * 0.01
    return total

def money_check(insert_c, cost) :
    if insert_c >= cost :
        change = round(insert_c - cost)
        print(f"잔돈 : {change}")
        return True
    else :
        print("잔액 부족 ")
        return False

def make_coffee(dr, ing) :
    """재료 차감 쳌!"""
    for item in ing :
        menu.resources[item] -= ing[item]
    print(f"주문하신 {dr} 나왔습니다 - ! ")

def coffee_dsil() :
    coffee_continue = True

    while coffee_continue :
        drink = input("뭐 드실 ?(espresso/latte/cappuccino) : ")
        if drink == "off" :
            coffee_continue = False
        elif drink == "report" :
            print(f"water : {menu.resources['water']}")
            print(f"milk : {menu.resources['milk']}")
            print(f"coffee : {menu.resources['coffee']}")
        else :
            chosen = menu.MENU[drink]
            if resource_suff(chosen["ingredients"]) :
                money = process_coin()
                if money_check(money, menu.MENU[drink]["cost"]) :
                    make_coffee(drink, chosen["ingredients"])

coffee_dsil()

 

☕️ menu.py

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,
}

 

 

☕️ 실행 결과