-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (45 loc) · 1.86 KB
/
app.py
File metadata and controls
57 lines (45 loc) · 1.86 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
48
49
50
51
52
53
54
55
56
57
from flask import Flask,request ,render_template , jsonify
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template('index.html')
@app.route('/math',methods=['POST'])
def math_ops():
if(request.method == 'POST'):
ops = request.form['operation']
num1 = int(request.form['num1'])
num2 = int(request.form['num2'])
if ops == 'add':
r = num1+num2
result = "The sum of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'subtract':
r = num1-num2
result = "The subtract of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'multiply':
r = num1*num2
result = "The multiply of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'divide':
r = num1/num2
result = "The divide of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
return render_template('results.html' , result = result)
@app.route('/postman_action',methods=['POST'])
def math_ops1():
if(request.method == 'POST'):
ops = request.json['operation']
num1 = int(request.json['num1'])
num2 = int(request.json['num2'])
if ops == 'add':
r = num1+num2
result = "The sum of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'subtract':
r = num1-num2
result = "The subtract of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'multiply':
r = num1*num2
result = "The multiply of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
if ops == 'divide':
r = num1/num2
result = "The divide of " + str(num1) + 'and ' + str(num2) + "is " + str(r)
return jsonify(result)
if __name__=="__main__":
app.run(host="0.0.0.0")