Special Numbers

Numbersapi is a great API full of fun facts about numbers and dates. With the help of webbrowser library we can then open these links right from the python terminal.

Here is a simply code that uses requests, json and webbrowser libraries.


>>> f = r"http://numbersapi.com/42"
>>> data = requests.get(f)
>>> data.text

You can use random to get random results
Also you can use 4 categories (it will default to trivia if not mentioned)
>>> f = r"http://numbersapi.com/random?json"
>>> f = r"http://numbersapi.com/random/date?json"
>>> f = r"http://numbersapi.com/random/year?json"
>>> f = r"http://numbersapi.com/random/math?json"

If you need a refresher on user defined functions lesson in Python here is a link to our Defining Functions Lesson.

Source of API: NumbersAPI

Recommended Posts