INNER CODE UNIT · Python

calculator

victordibia/designing-multiagent-systems · course/samples/hello_world/autogen_core/app.py:27

async def calculator(a: float, b: float, operator: str) -> str:
    """Perform basic arithmetic operations."""
    try:
        if operator == '+':
            return str(a + b)
        elif operator == '-':
            return str(a - b)
        elif operator == '*':
            return str(a * b)
        elif operator == '/':
            if b == 0:
                return 'Error: Division by zero'
            return str(a / b)
        else:
            return 'Error: Invalid operator. Please use +, -, *, or /'
    except Exception as e:
        return f'Error: {str(e)}'

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…