diff --git a/persistent_auditor.py b/persistent_auditor.py index cb8f6ce..c25e082 100644 --- a/persistent_auditor.py +++ b/persistent_auditor.py @@ -39,15 +39,24 @@ def generate_report(total_units, failed_attempts): def load_inventory(): try: with open("inventory.txt", "r") as inventory_file: - return int(inventory_file.readline().strip()) + inventory = int(inventory_file.readline().strip()) + history_line = inventory_file.readline().strip() + history = [] if not history_line else [int(value) for value in history_line.split(",")] + return inventory, history except FileNotFoundError: - return 0 + return 0, [] -inventory = load_inventory() +def save_inventory(inventory, transaction_history): + with open("inventory.txt", "w") as inventory_file: + inventory_file.write(f"{inventory}\n") + inventory_file.write(",".join(str(quantity) for quantity in transaction_history)) + inventory_file.write("\n") + + +inventory, transaction_history = load_inventory() total_units = 0 failed_attempts = 0 -transaction_history = [] print("=== Stock Auditor ===") print("Type 'quit' to exit.\n") @@ -56,6 +65,7 @@ while True: quantity = get_valid_input() if quantity == "quit": + save_inventory(inventory, transaction_history) break tax = calculate_tax(quantity)