Files
inf1103-labs/modular_auditor.py
T

65 lines
1.5 KiB
Python

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)