API

This is an API of a random math problem generator. We could use these to create random quiz questions for people who save notes for math in our project.

import requests

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

querystring = {"type":"html"}

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

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

print(response.text)
print(response.json())
{"title":"<h2>Risky moon<\/h2>","problem":"<div class=\"problem_content\" role=\"problem\">\r\n<p>\nA moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$. \n<\/p>\n\n<p>\nThere are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.\n<\/p>\n\n<p>\nAll stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If <var>d<\/var> is the length of the road between two stations, $\\left(\\frac{d}{\\pi r}\\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.\n<\/p>\n\n<p>\nA direct journey from  the North Pole station to the South Pole station has the length $\\pi r$ and risk 1. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:<\/p>\n\\[\n\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2+\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2=0.5\n\\]\n\n<p>\nThe minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.\n<\/p>\n\n<p>\nYou are given that $M(7)=0.1784943998$  rounded to 10 digits behind the decimal point. \n<\/p>\n\n<p>\nFind $\\displaystyle{\\sum_{n=1}^{15}M(2^n-1)}$.\n<\/p>\n\n<p>\nGive your answer rounded to 10 digits behind the decimal point in the form a.bcdefghijk.\n<\/p>\n\n\n<\/div>"}
{'title': '<h2>Risky moon</h2>', 'problem': '<div class="problem_content" role="problem">\r\n<p>\nA moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$. \n</p>\n\n<p>\nThere are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.\n</p>\n\n<p>\nAll stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If <var>d</var> is the length of the road between two stations, $\\left(\\frac{d}{\\pi r}\\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.\n</p>\n\n<p>\nA direct journey from  the North Pole station to the South Pole station has the length $\\pi r$ and risk 1. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:</p>\n\\[\n\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2+\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2=0.5\n\\]\n\n<p>\nThe minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.\n</p>\n\n<p>\nYou are given that $M(7)=0.1784943998$  rounded to 10 digits behind the decimal point. \n</p>\n\n<p>\nFind $\\displaystyle{\\sum_{n=1}^{15}M(2^n-1)}$.\n</p>\n\n<p>\nGive your answer rounded to 10 digits behind the decimal point in the form a.bcdefghijk.\n</p>\n\n\n</div>'}

Questions

Each random math problem has a title as well as the actual problem. They are both outputted using html, as seen through the use of <div> and <p> tags.

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

print("title: ")
print(title)
title: 
<h2>Risky moon</h2>
print("Problem: ")
print(problem)
Problem: 
<div class="problem_content" role="problem">
<p>
A moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$. 
</p>

<p>
There are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.
</p>

<p>
All stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If <var>d</var> is the length of the road between two stations, $\left(\frac{d}{\pi r}\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.
</p>

<p>
A direct journey from  the North Pole station to the South Pole station has the length $\pi r$ and risk 1. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:</p>
\[
\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2+\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2=0.5
\]

<p>
The minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.
</p>

<p>
You are given that $M(7)=0.1784943998$  rounded to 10 digits behind the decimal point. 
</p>

<p>
Find $\displaystyle{\sum_{n=1}^{15}M(2^n-1)}$.
</p>

<p>
Give your answer rounded to 10 digits behind the decimal point in the form a.bcdefghijk.
</p>


</div>