25 lines
462 B
Python
25 lines
462 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
|
||
INDEX = "营业利润率(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
利润总额: float
|
||
营业收入: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
result = p.利润总额 / p.营业收入 * 100
|
||
return round(result, 6)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|