Files
AI_code/mymath.py

29 lines
760 B
Python

def multiply(a, b):
"""Return the product of two numbers."""
return a * b
def divide(a, b):
"""Return a divided by b. Raises ValueError if b is zero."""
if b == 0:
raise ValueError("Division by zero is not allowed")
return a / b
if __name__ == "__main__":
# Test multiply
result = multiply(3, 4)
print(f"3 * 4 = {result}")
assert result == 12, "Multiplication test failed"
# Test divide
result = divide(10, 2)
print(f"10 / 2 = {result}")
assert result == 5, "Division test failed"
# Test divide by zero
try:
divide(5, 0)
print("ERROR: Expected ValueError not raised")
except ValueError as e:
print(f"Caught expected error: {e}")
print("All tests passed.")