-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_flask.py
33 lines (26 loc) · 1.1 KB
/
app_flask.py
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
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST']) # To render Homepage
def home_page():
return "Home Page"
@app.route('/via_postman', methods=['POST']) # for calling the API
def calculator():
if (request.method=='POST'):
operation=request.json['operation']
num1=int(request.json['num1'])
num2 = int(request.json['num2'])
if(operation=='add'):
r=num1+num2
result= 'the sum of '+str(num1)+' and '+str(num2) +' is '+str(r)
if (operation == 'subtract'):
r = num1 - num2
result = 'the difference of ' + str(num1) + ' and ' + str(num2) + ' is ' + str(r)
if (operation == 'multiply'):
r = num1 * num2
result = 'the product of ' + str(num1) + ' and ' + str(num2) + ' is ' + str(r)
if (operation == 'divide'):
r = num1 / num2
result = 'the quotient when ' + str(num1) + ' is divided by ' + str(num2) + ' is ' + str(r)
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)