티스토리 뷰
Coffee Machine Documentation
MenuItem Class Attributes: (str) The name of the drink. e.g. “latte” (float) The price of the drink. e.g 1.5 (dictionary) The ingredients and amounts required to make the drink. e.g. {“water”: 100, “coffee”: 16} Menu Class Methods: Returns a
docs.google.com
Attributes:
- name
(str) The name of the drink.
e.g. “latte”
- cost
(float) The price of the drink.
e.g 1.5
- ingredients
(dictionary) The ingredients and amounts required to make the drink.
e.g. {“water”: 100, “coffee”: 16}
Menu Class
Methods:
- get_items()
Returns all the names of the available menu items as a concatenated string.
e.g. “latte/espresso/cappuccino”
- find_drink(order_name)
Parameter order_name: (str) The name of the drinks order.
Searches the menu for a particular drink by name. Returns a MenuItem object if it exists, otherwise returns None.
CoffeeMaker Class
Methods:
- report()
Prints a report of all resources.
e.g.
Water: 300ml
Milk: 200ml
Coffee: 100g
- is_resource_sufficient(drink)
Parameter drink: (MenuItem) The MenuItem object to make.
Returns True when the drink order can be made, False if ingredients are insufficient.
e.g.
True
- make_coffee(order)
Parameter order: (MenuItem) The MenuItem object to make.
Deducts the required ingredients from the resources.
MoneyMachine Class
Methods:
- report()
Prints the current profit
e.g.
Money: $0
- make_payment(cost)
Parameter cost: (float) The cost of the drink.
Returns True when payment is accepted, or False if insufficient.
e.g. False
from menu import Menu, MenuItem
from coffee_maker import CoffeeMaker
from money_machine import MoneyMachine
menu = Menu()
coffee_maker = CoffeeMaker()
money_machine = MoneyMachine()
is_on = True
while is_on:
order = input(f"What would you like? ({menu.get_items()}):").lower()
if order == "off":
is_on = False
elif order == "report":
coffee_maker.report()
money_machine.report()
else:
drink = menu.find_drink(order)
if coffee_maker.is_resource_sufficient(drink):
if 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
menu = Menu()
coffee_maker = CoffeeMaker()
money_machine = MoneyMachine()
is_on = True
while is_on:
order = input(f"What would you like? ({menu.get_items()}):").lower()
if order == "off":
is_on = False
elif order == "report":
coffee_maker.report()
money_machine.report()
else:
drink = menu.find_drink(order)
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)
'Test > Python(20220101~)' 카테고리의 다른 글
Days17.Method in Class (0) | 2022.02.14 |
---|---|
Days17. Create our own 'Class' (0) | 2022.02.13 |
** Find, install and publish Python packages with the Python Package Index (0) | 2022.02.12 |
Days16_OOP : Object Oriented Programming (0) | 2022.02.05 |
Days15_Coffee Machine (0) | 2022.01.30 |
- Total
- Today
- Yesterday
- 배열
- vmware.powercli
- dezoomify
- artandculture
- dp-1
- insert
- virt-sysprep
- fromkeys
- 부동없이
- 중복제거
- storage
- 스토리지
- EXA
- 차집합
- set()
- LIST
- oracle
- cloud-init
- 3par
- powercli
- 변수화
- powershell
- Join
- 대소문자
- exadata
- dp-2
- 읽어오기
- sysprep
- vmware
- 정렬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |