Create calc.py

This commit is contained in:
OusmBlueNinja 2023-09-21 18:49:53 -05:00 committed by GitHub
parent c4f183a6aa
commit bce0fe8fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

30
packages/calc.py Normal file
View File

@ -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}")