File size: 745 Bytes
b6dcc89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from fastapi import APIRouter

# Create the router for calculator endpoints
router = APIRouter(
    prefix="/calculate",
    tags=["Calculator"] 
)

@router.get("/add")
def add_numbers(a: float, b: float):
    """
    Adds two numbers, 'a' and 'b'.
    
    Query parameters: a (float), b (float)
    """
    result = a + b
    return {
        "operation": "addition",
        "a": a,
        "b": b,
        "result": result
    }

@router.get("/subtract")
def subtract_numbers(a: float, b: float):
    """
    Subtracts number 'b' from number 'a' (a - b).
    
    Query parameters: a (float), b (float)
    """
    result = a - b
    return {
        "operation": "subtraction",
        "a": a,
        "b": b,
        "result": result
    }