From ee697ecd0817cd3844d20091c5d82a76609da6c6 Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Fri, 18 Sep 2026 14:35:08 +0800 Subject: [PATCH] added modular_auditor.py and updated Dockerfile to use new script --- Dockerfile | 5 ++-- modular_auditor.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 modular_auditor.py diff --git a/Dockerfile b/Dockerfile index db1d341..7c24262 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM python:3.11-slim WORKDIR /app -COPY auditor.py . - -CMD ["python", "auditor.py"] +COPY modular_auditor.py . +CMD ["python", "modular_auditor.py"] diff --git a/modular_auditor.py b/modular_auditor.py new file mode 100644 index 0000000..13efc1b --- /dev/null +++ b/modular_auditor.py @@ -0,0 +1,64 @@ +def get_valid_input(): + global failed_attempts + + while True: + user_input = input("Enter stock quantity: ").strip() + + if user_input.lower() == "quit": + return "quit" + + if not user_input.isdigit(): + print("Error: Invalid input. Please enter a non-negative integer.\n") + failed_attempts += 1 + continue + + quantity = int(user_input) + + if quantity < 0: + print("Error: Negative numbers are not allowed.\n") + failed_attempts += 1 + continue + + return quantity + + +def process_delivery(current_total, new_value): + return current_total + new_value + + +def calculate_tax(amount): + return amount * 0.10 + + +def generate_report(total_units, failed_attempts): + print("\n--- Audit Report ---") + print(f"Total Units Processed: {total_units}") + print(f"Failed/Rejected Entries: {failed_attempts}") + + +inventory = 0 +total_units = 0 +failed_attempts = 0 + +print("=== Stock Auditor ===") +print("Type 'quit' to exit.\n") + +while True: + quantity = get_valid_input() + + if quantity == "quit": + break + + tax = calculate_tax(quantity) + + inventory = process_delivery(inventory, quantity) + total_units = process_delivery(total_units, quantity) + + print(f"Stock added. Current inventory: {inventory}") + print(f"Tax on this delivery: ${tax:.2f}\n") + + if inventory > 500: + print(f"ALERT: Overstock detected! Inventory ({inventory}) exceeds 500 units.") + break + +generate_report(total_units, failed_attempts)