-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.py
More file actions
31 lines (26 loc) · 1.01 KB
/
Copy pathinventory.py
File metadata and controls
31 lines (26 loc) · 1.01 KB
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
from enums import SupplyType
from constants import RESTOCK_THRESHOLD
class Inventory:
def __init__(self):
self.stock = {
SupplyType.MEDICATION: 50,
SupplyType.BANDAGES: 60,
SupplyType.OXYGEN: 40,
SupplyType.SURGICAL_KIT: 15,
SupplyType.BLOOD: 25
}
def consume(self, supply_type, amount=1):
if self.stock[supply_type] >= amount:
self.stock[supply_type] -= amount
return True
return False
def restock(self, supply_type, amount):
self.stock[supply_type] += amount
def is_low(self, supply_type):
return self.stock[supply_type] <= RESTOCK_THRESHOLD[supply_type]
def __repr__(self):
lines = ["Inventory:"]
for supply, qty in self.stock.items():
low = "LOW" if self.is_low(supply) else ""
lines.append(f" {supply.value:<15}: {qty}{low}")
return "\n".join(lines)