How to make computation in website

Hello,

I am pretty new in web development and I would like to ask how to do the following. I don't doubt I could somehow make it work, but I would like to know if some better/standard approach exists.

I want to have math problems on my website.

Something like this

Problem:

Compute third side of triangle with two sides being {a} and {b} and with angle between them being {gamma}

Parameters {a}, {b}, {gamma} I would like to insert form somewhere - say database or randomly generated or something like that. After that there should be a solution

Solution:

Just use cosine theorem $$c^2={a}^2+{b}^2-2*{a}*{b}*\cos({gamma})$$

The result is {c}

Again {a}, {b}, {gamma} should have the values inserted and then there should be a computation that produces the result for {c}.

I am using django and what I have right now is this model"

class Problem(models.Model):

name = models.CharField(max_length=256)

problem =  models.TextField()

solution = models.TextField()

values = models.TextField(null = True)

computations = models.TextField(null=True)

and I am thinking about somehow representing the values by json like this

{

"a": 5,

"b": 7,

"gamma": 55

}

computation by text that I translate into javascript code somehow

{

"c": "Math.sqrt(a*a+b*b-2*a*b*Math.cos(gamma))"

}

and then make javascript in the web page to get these, recognize the values which are to be substituted inside the text (I was thinking about using ${a$} symbols) and substituting/computing what it should.

Thank to all the repliers in advance:)