import requests

BASE_URL = "http://api.mathjs.org/v4/"

# # Using GET
# my_expr = "2*(7+3)"

# r = requests.get(BASE_URL, params={"expr": my_expr})
# print(r.status_code)
# print(r.headers['content-type'])
# print(r.encoding)
# print(r.text)


# Using POST
# Set the Content-Type header to 'application/json'
headers = {'Content-Type': 'application/json'}
#payload = '{"expr":["a = 2 + 3", "5 * 2"], "precision": 3}'
payload = '''{
    "expr": [
      "a = 2 * (2 + 1)",
      "a / 2",
      "100 / 3",
      "b = 2 * [1, 2; 3, 4]"
    ],
    "precision": 5
  }'''

r = requests.post(BASE_URL, data=payload, headers=headers)
print(r.status_code)
print(r.headers['content-type'])
print(r.encoding)
print(r.text)

import json
res = json.loads(r.text)
print(res)
print(res["result"][1])


