[uemy] python 부트캠프 _ section 15 _로컬 개발 환경 설정과 커피머신

Dreamer ·2022년 8월 22일
0
post-thumbnail

01. 파이참의 매력 포인트

  • spell check
  • More space
  • built-in Linter : 지정된 코딩 스타일에 맞지 않는 코드를 골라냄.
  • Local History : 지난 12시간 동안 진행한 코드들을 확인할 수 있다.
  • View Structure : 코드의 모든 변수와 함수가 분류되어 수백 줄이 넘는 긴 코드에서 쉽게 함수,변수를 찾을 수 있다.
  • Refactor Rename : 변수나 함수의 이름을 변경하고 싶을 때, 한 꺼번에 자동으로 고쳐줌. refactor -> rename 한번에 고칠 수 있음.

02. coffe machine project

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,
}
money = 0


def is_resource_sufficient(order_ingredient):
    """Returns True when order can be made, False if ingredients are insufficient"""
    is_enough = True
    for item in order_ingredient:
        if order_ingredient[item] >= resources[item]:
            print(f"Sorry there is not enough {'item'}.")
            is_enough = False
    return is_enough


def process_coins():
    """Returns the total calculated from coins inserted."""
    print("Please insert coins.")
    total = int(input("how many quarters?: ")) * 0.25
    total += int(input("how many dimes?: ")) * 0.1
    total += int(input("how many nickles?: ")) * 0.05
    total += int(input("how many penniess?: ")) * 0.01
    return total


def is_transaction_succesful(money_received, drink_cost):
    """Return True when the payment is accepted, or False money is insufficient."""
    if money_received >= drink_cost:
        change = round(money_received-drink_cost,2)
        print(f"Here is ${change} in change.")
        global money
        money += drink_cost
        return True

    else:
        print("Sorry that's not enough money. Money refunded.")
        return False


def make_coffee(drink_name, order_ingredients):
    """Deduct the required ingredients from the resources."""
    for item in order_ingredients:
        resources[item] -= order_ingredients[item]
    print(f"Here is your {drink_name} ")


# TODO : 1. Print report.
# TODO : 2. Check resources sufficient?
# TODO : 3. Process coins.
# TODO : 4. Check transaction successful?
# TODO : 5. Make Coffee.


is_on = True
while is_on :
    choice = input("What would you like? (espresso/latte/cappuccino): ")
    if choice == "off":
        is_on = False
    elif choice == "report":
       print(f"Water: {resources['water']}ml")
       print(f"Milk: {resources['milk']}ml")
       print(f"Coffee: {resources['coffee']}g")
       print(f"Money: ${money}")
    else:
        drink = MENU[choice]
        if is_resource_sufficient(drink["ingredients"]):
            payment = process_coins()
            if is_transaction_succesful(payment, drink["cost"]):
                make_coffee(choice, drink["ingredients"])

git : https://github.com/yoooooooonji/Python-bootcamp

profile
To be a changer who can overturn world

0개의 댓글