-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_manager.py
46 lines (34 loc) · 1.28 KB
/
token_manager.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
# This section was built with some help from Chat GPT. I wanted to see what it could create
# I have actually just ended up using a dictionary on its own and not a class for the tokens.
class TokenManager:
def __init__(self, initial_tokens):
self.tokens = initial_tokens
def add_tokens(self, tokens_to_add):
for color, quantity in tokens_to_add.items():
self.tokens[color] += quantity
def remove_tokens(self, tokens_to_remove):
for color, quantity in tokens_to_remove.items():
if self.tokens[color] < quantity:
raise ValueError(f"Not enough {color} tokens available")
self.tokens[color] -= quantity
"""
def get_tokens(self):
return self.tokens.copy()
"""
def __str__(self):
return str(self.tokens)
# Example usage:
"""
initial_tokens = {'red': 7, 'blue': 7, 'green': 7, 'white': 7, 'black': 7, 'gold': 5}
token_manager = TokenManager(initial_tokens)
print("Initial Tokens:")
print(token_manager)
tokens_to_add = {'red': 2, 'gold': 1}
token_manager.add_tokens(tokens_to_add)
print("\nAfter adding tokens:")
print(token_manager)
tokens_to_remove = {'green': 3, 'white': 2}
token_manager.remove_tokens(tokens_to_remove)
print("\nAfter removing tokens:")
print(token_manager)
"""