added modular_auditor.py and updated Dockerfile to use new script

This commit is contained in:
2026-09-18 14:35:08 +08:00
parent 4bae2ce67d
commit ee697ecd08
2 changed files with 66 additions and 3 deletions
+2 -3
View File
@@ -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"]
+64
View File
@@ -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)