-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
40 lines (31 loc) · 1.11 KB
/
utils.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
import logging
# Logger settings
def setup_logger(name, log_file=None, level=logging.INFO):
"""Function to setup as many loggers as you want"""
formatter = logging.Formatter('[%(asctime)s] {%(filename)s:%(lineno)d} [%(name)s] [%(levelname)s] --> %(message)s')
out_handler = logging.StreamHandler()
out_handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(out_handler)
if log_file:
handler = logging.FileHandler(log_file, encoding='utf8')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
logger = setup_logger("APIVendingMachine")
def calculate_change(change):
"""
Function that will return an array of
5,10,20,50 or 100 coins as change.
"""
# TODO can replace here with env variable for the
# coin types in order to change easier.
coins = []
for value in [100, 50, 20, 10, 5]:
coins.extend([value] * int(change / value))
change = change % value
return coins
if __name__ == '__main__':
change = 275
print(calculate_change(change))