Files
ai_vibe_conding/test.py
leifyung 40acd4ce82 Refactor functions into Calculator class
- Add Calculator class with add and multiply methods
- Maintain original functions for compatibility
- Update test code to use class interface
2026-03-04 18:29:53 +08:00

34 lines
1000 B
Python

class Calculator:
"""A calculator class that provides basic arithmetic operations."""
def add(self, a, b):
"""Return the sum of two numbers."""
return a + b
def multiply(self, a, b):
"""Return the product of two numbers."""
return a * b
def add_two_numbers(a, b):
"""Return the sum of two numbers."""
return a + b
def multiply_two_numbers(a, b):
"""Return the product of two numbers."""
return a * b
if __name__ == "__main__":
# Example usage with the Calculator class
calc = Calculator()
# Test addition using Calculator class
sum_result = calc.add(5, 3)
print(f"The sum is: {sum_result}")
# Test multiplication using Calculator class
product_result = calc.multiply(5, 3)
print(f"The product is: {product_result}")
# Also test the original functions for compatibility
print(f"Function add result: {add_two_numbers(5, 3)}")
print(f"Function multiply result: {multiply_two_numbers(5, 3)}")