diff --git a/packages/calc.py b/packages/calc.py new file mode 100644 index 0000000..7c4b698 --- /dev/null +++ b/packages/calc.py @@ -0,0 +1,30 @@ +# ["calc", "packages.calc", ["calc"]] +# Made By YourNameHere + +def calculator(command: list): + if len(command) != 3: + print("Usage: calculator [operand1] [operator] [operand2]") + return + + operand1 = float(command[0]) + operator = command[1] + operand2 = float(command[2]) + + result = None + + if operator == "+": + result = operand1 + operand2 + elif operator == "-": + result = operand1 - operand2 + elif operator == "*": + result = operand1 * operand2 + elif operator == "/": + if operand2 == 0: + print("Error: Division by zero is not allowed.") + return + result = operand1 / operand2 + else: + print("Invalid operator. Supported operators are +, -, *, /") + return + + print(f"Result: {operand1} {operator} {operand2} = {result:.2f}")