This is a FastAPI-powered Number Classification API that takes an integer as input and returns mathematical properties of the number along with a fun fact.
- Determines whether the number is prime.
- Checks if the number is an Armstrong number.
- Identifies if the number is perfect.
- Classifies the number as odd or even.
- Calculates the sum of digits.
- Retrieves a fun fact about the number from Numbers API.
Query Parameter:
number
(integer) - The number to classify.
Request:
GET /api/classify-number?number=371
Response:
{
"number": 371,
"is_prime": false,
"is_perfect": false,
"properties": ["armstrong", "odd"],
"digit_sum": 11,
"fun_fact": "371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371"
}
Request:
GET /api/classify-number?number=abc
Response:
{
"number": "abc",
"error": true
}
git clone https://github.com/TYDev01/HNG12_Stage_1.git
cd HNG12_Stage_1
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
pip install -r requirements.txt
uvicorn main:app --reload
Open your browser or use Postman to visit:
http://127.0.0.1:8000/api/classify-number?number=371
To deploy this API, you can use Render, Railway, Vercel, or DigitalOcean. Ensure the API is publicly accessible.
- Python 🐍
- FastAPI 🚀
- Uvicorn
- Numbers API
MIT License © 2025 TYDev
Feel free to fork, submit PRs, or open issues if you have suggestions or find bugs! 🎉