From f76f213b23e46e34da47ccab4fb6f7500ba21c3a Mon Sep 17 00:00:00 2001 From: Vyvy-vi Date: Mon, 9 Aug 2021 14:35:11 +0530 Subject: [PATCH] feat: add route for diceroll --- routes/diceroll.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 routes/diceroll.py diff --git a/routes/diceroll.py b/routes/diceroll.py new file mode 100644 index 0000000..2e2e20b --- /dev/null +++ b/routes/diceroll.py @@ -0,0 +1,19 @@ +import random +from fastapi import APIRouter, Query + +router = APIRouter() + + +@router.get("/diceroll") +def roll_dice( + num: int = Query(1, ge=1, le=10000), + sides: int = Query(6, ge=3, le=10000) + ): + return { + "task": f"diceroll - d{sides} x {num}", + "result": random.choices( + range(1, sides + 1), + k = num + ) + } +