Create calc.py
This commit is contained in:
parent
c4f183a6aa
commit
bce0fe8fad
30
packages/calc.py
Normal file
30
packages/calc.py
Normal 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}")
|
Loading…
Reference in New Issue
Block a user