-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (25 loc) · 814 Bytes
/
app.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
from flask import Flask,request,render_template,jsonify
import json
obj = Flask(__name__)
@obj.route('/')
def welcome():
return "Welcome to the Flask"
@obj.route('/calculate', methods=["GET", "POST"])
def math_operator():
operation = request.json["operation"] # written json cause we are going to request using postman
number1 = int(request.json["number1"])
number2 = int(request.json["number2"])
if operation == "add":
result = number1+number2
elif operation == "sub":
result = number1 - number2
elif operation == "mul":
result = number1*number2
elif operation == "div":
result = number1 / number2
else:
result = "Please select valide opeartion!"
return jsonify(result)
print(__name__)
if __name__ == "__main__":
obj.run()