Fetching Questions
As we discussed above, we'll be using the Open Trivia DB API to get the questions. Head over to their API, select the number of questions, category, and difficulty. The question type should be Multiple Choice and the encoding should be Default Encoding. Click on Generate API URL and you'll get an API URL.
Sample API URL: https://opentdb.com/api.php?amount=10&type=multiple
For fetching the questions, we'll be using requests module. It can be installed as:
Let's create a Python file quiz_data.py to fetch the quiz questions and answers using the API URL generated above.
The JSON data contains a dictionary with two keys - response_code and results. The response_code tells developers what the API is doing. The results is a list we are interested in. So, we have stored the value of results in a variable question_data.
3
