-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalcAPI.py
More file actions
47 lines (37 loc) · 1.25 KB
/
calcAPI.py
File metadata and controls
47 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, jsonify, request
calcAPI = Flask(__name__)
@calcAPI.route('/rut', methods=['POST'])
def root_of():
data = request.get_json()
ip1 = data["input_1"]
ip2 = data["input_2"]
res = ip1 ** (1 / ip2)
if ip2 == 2:
op = f"The value of square root of {ip1} is"
elif ip2 == 3:
op = f"The value of cube root of {ip1} is"
else:
op = f"The value of {ip2} root of {ip1} is"
result = {op: res}
return result
@calcAPI.route('/expo', methods=['POST'])
def expo():
data = request.get_json()
ip1 = data["input_1"]
ip2 = data["input_2"]
res = ip1 ** ip2
result = {f"The value of {ip1} to the power {ip2} is": res}
return result
@calcAPI.route('/log', methods=['POST'])
def log():
data = request.get_json()
ip1 = data["input_1"]
ip2 = data["input_2"]
n = 1000000000.0
ln_ip1 = n * ((ip1 ** (1 / n)) - 1)
ln_ip2 = n * ((ip2 ** (1 / n)) - 1)
res = ln_ip1 / ln_ip2
result = {f"The value of log {ip1} to the base {ip2} is": res}
return result
if __name__ == '__main__':
calcAPI.run(debug=True)