-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbgs_vending_machine.py
50 lines (36 loc) · 1.47 KB
/
bgs_vending_machine.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# python 3.5.2
# -*- coding: utf-8 -*-
class VendingMachine(object):
def __init__(self):
# Initialize
self.beverage_list = {1: {'name': 'Coke', 'price': 300},
2: {'name': 'Sprite', 'price': 200},
3: {'name': 'Coco-pam', 'price': 200},
4: {'name': 'Gatorade', 'price': 300},
5: {'name': 'Red-bull', 'price': 200}
}
self.beverage_name = None
self.beverage_price = None
self.coin = None
self.beverage_name = None
self.power = 1
print('Machine is ready !!')
def beverage_out(self, option):
self.beverage_name = self.beverage_list[option]['name']
self.beverage_price = self.beverage_list[option]['price']
if self.coin <= self.beverage_price:
self.power = 0
self.coin -= self.beverage_price
print(self.beverage_name + " is out")
print('exchange is ', self.coin, ' won')
def start_machine(self):
self.coin = int(input('Insert the coin : '))
while self.power:
option = int(input('1. Coke 2. Sprite 3. Coco-pam 4. Gatorade 5. Red-bull 6. Exit'))
if option == 6:
print(self.coin, 'won is out')
break
self.beverage_out(option)
if __name__ == '__main__':
vending_machine = VendingMachine()
vending_machine.start_machine()