25 lines
468 B
Python
25 lines
468 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
|
||
INDEX = "人均GDP/全国平均GDP(倍)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
人均GDP: float
|
||
全国平均GDP: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
result = p.人均GDP / p.全国平均GDP
|
||
return round(result, 2)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|