forked from aeranghang/vendingmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm.py
More file actions
27 lines (24 loc) · 897 Bytes
/
Copy pathvm.py
File metadata and controls
27 lines (24 loc) · 897 Bytes
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
class VendingMachine:
def __init__(self):
self._change = 0
def run(self, raw):
tokens = raw.split(" ")
cmd, params = tokens[0], tokens[1:]
if cmd == "잔액":
return "잔액은 " + str(self._change) + "원입니다"
elif cmd == "동전":
coin = params[0]
self._change += int(coin)
return coin + "원을 넣었습니다"
elif cmd == "음료":
known_beverage = "커피"
price = 150
beverage = params[0]
if beverage != known_beverage:
return "알 수 없는 음료입니다"
if self._change < price:
return "잔액이 부족합니다"
self._change = self._change - price
return beverage + "가 나왔습니다"
else:
return "알 수 없는 명령입니다"