MathQuiz API provides simple endpoints that generate a random arithmetic problem and its solution.
- Python 3.8+
- FastAPI (recommended install:
fastapi[standard])
Install dependencies:
pip install "fastapi[standard]"Start the development server from the project folder:
uvicorn main:app --reloadOpen the interactive API docs at: http://127.0.0.1:8000/docs
All endpoints accept these optional query parameters:
min(float) — lower bound (default0.0)max(float) — upper bound (default100.0)decimals(bool) — whether to generate decimal numbers (defaultfalse)
Available endpoints (GET):
/add— addition/subtract— subtraction/multiply— multiplication/divide— division (division avoids zero divisors; invalid ranges return400)
Example requests:
# integer addition between 10 and 50
curl "http://127.0.0.1:8000/add?min=10&max=50&decimals=false"
# decimal division between 1 and 10
curl "http://127.0.0.1:8000/divide?min=1&max=10&decimals=true"Responses are JSON objects with these fields:
task: the problem as a string (e.g. "40 + 50" or "3.14 / 2.00")solution: the evaluated result (integers for integer mode, rounded floats whendecimals=true)
Example response (integers):
{
"task": "40 + 50",
"solution": 90
}Example response (decimals):
{
"task": "3.14 / 2.00",
"solution": 1.57
}