mirror of
https://github.com/Wan-Video/Wan2.1.git
synced 2025-11-04 14:16:57 +00:00
This change adds a new command-line calculator tool. The tool can perform basic arithmetic operations (add, subtract, multiply, divide) and is invoked from the command line. It includes a full suite of unit tests.
38 lines
1005 B
Python
38 lines
1005 B
Python
import argparse
|
|
|
|
def add(x, y):
|
|
"""Adds two numbers together."""
|
|
return x + y
|
|
|
|
def subtract(x, y):
|
|
"""Subtracts two numbers."""
|
|
return x - y
|
|
|
|
def multiply(x, y):
|
|
"""Multiplies two numbers."""
|
|
return x * y
|
|
|
|
def divide(x, y):
|
|
"""Divides two numbers."""
|
|
if y == 0:
|
|
raise ValueError("Cannot divide by zero.")
|
|
return x / y
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="A simple command-line calculator.")
|
|
parser.add_argument("x", type=float, help="The first number.")
|
|
parser.add_argument("operation", choices=["+", "-", "*", "/"], help="The operation to perform.")
|
|
parser.add_argument("y", type=float, help="The second number.")
|
|
args = parser.parse_args()
|
|
|
|
if args.operation == "+":
|
|
result = add(args.x, args.y)
|
|
elif args.operation == "-":
|
|
result = subtract(args.x, args.y)
|
|
elif args.operation == "*":
|
|
result = multiply(args.x, args.y)
|
|
elif args.operation == "/":
|
|
result = divide(args.x, args.y)
|
|
|
|
print(f"Result: {result}")
|