#!/usr/bin/env python3 """ Calculator CLI - A simple command-line calculator. NOTE: This file contains intentional bugs for testing purposes. Usage: python -m calculator.main 10 5 add python -m calculator.main 10 5 sub python -m calculator.main 10 5 mul python -m calculator.main 10 5 div """ import sys from calculator.operations import add, subtract, multiply, divide def get_operation(op_name: str): """ Get the operation function by name. BUG: No validation - invalid operation names cause KeyError! """ operations = { "add": add, "sub": subtract, "mul": multiply, "div": divide, # BUG: 'power' is implemented in operations.py but not exposed here } # BUG: Should handle KeyError gracefully return operations[op_name] def main(): """Main entry point.""" if len(sys.argv) != 4: print("Usage: python -m calculator.main ") print("Operations: add, sub, mul, div") sys.exit(1) # BUG: No validation that a and b are valid numbers a = float(sys.argv[1]) b = float(sys.argv[2]) op_name = sys.argv[3] # BUG: This will crash with KeyError for invalid operation operation = get_operation(op_name) result = operation(a, b) print(f"Result: {result}") if __name__ == "__main__": main()