API Usage

We will be using a random math problem generator for our API. This could be used to create a base set of flashcards for users for our project.

import requests

url = "https://random-math-problem.p.rapidapi.com/random-problem"

querystring = {"type":"html"}

headers = {
	"X-RapidAPI-Key": "8677538c65mshfd1d85d7adf047fp17a8a1jsn7a54a04df28c",
	"X-RapidAPI-Host": "random-math-problem.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)

title = response.json().get('title')
problem = response.json().get('problem')

print("Printing response.text")
print(response.text)
Printing response.text
{"title":"<h2>Generalised Hamming Numbers<\/h2>","problem":"<div class=\"problem_content\" role=\"problem\">\r\n<p>A Hamming number is a positive number which has no prime factor larger than 5.<br>\nSo the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.<br>\nThere are 1105 Hamming numbers not exceeding 10<sup>8<\/sup>.<\/p>\n\n<p>We will call a positive number a generalised Hamming number of type <var>n<\/var>, if it has no prime factor larger than <var>n<\/var>.<br>\nHence the Hamming numbers are the generalised Hamming numbers of type 5.<\/p>\n\n<p>How many generalised Hamming numbers of type 100 are there which don't exceed 10<sup>9<\/sup>?<\/p>\n<\/div>"}
print("Printing response.json()")
print(response.json())
Printing response.json()
{'title': '<h2>Generalised Hamming Numbers</h2>', 'problem': '<div class="problem_content" role="problem">\r\n<p>A Hamming number is a positive number which has no prime factor larger than 5.<br>\nSo the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.<br>\nThere are 1105 Hamming numbers not exceeding 10<sup>8</sup>.</p>\n\n<p>We will call a positive number a generalised Hamming number of type <var>n</var>, if it has no prime factor larger than <var>n</var>.<br>\nHence the Hamming numbers are the generalised Hamming numbers of type 5.</p>\n\n<p>How many generalised Hamming numbers of type 100 are there which don\'t exceed 10<sup>9</sup>?</p>\n</div>'}

Organized Question

Each question has a title and a problem. The title is the name of the project, and the problem stores the actual question. Printing each thing will allow the user to see the specific HTML in the

print("Printing a title")
print(title) 
Printing a title
<h2>Generalised Hamming Numbers</h2>
print("Printing a problem")
print(problem)
Printing a problem
<div class="problem_content" role="problem">
<p>A Hamming number is a positive number which has no prime factor larger than 5.<br>
So the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.<br>
There are 1105 Hamming numbers not exceeding 10<sup>8</sup>.</p>

<p>We will call a positive number a generalised Hamming number of type <var>n</var>, if it has no prime factor larger than <var>n</var>.<br>
Hence the Hamming numbers are the generalised Hamming numbers of type 5.</p>

<p>How many generalised Hamming numbers of type 100 are there which don't exceed 10<sup>9</sup>?</p>
</div>