-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
40 lines (35 loc) · 967 Bytes
/
api.py
File metadata and controls
40 lines (35 loc) · 967 Bytes
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
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/add', methods=['POST'])
def add():
data = request.get_json()
a = data['a']
b = data['b']
result = a + b
return jsonify({'result': result})
@app.route('/subtract', methods=['POST'])
def subtract():
data = request.get_json()
a = data['a']
b = data['b']
result = a - b
return jsonify({'result': result})
@app.route('/multiply', methods=['POST'])
def multiply():
data = request.get_json()
a = data['a']
b = data['b']
result = a * b
return jsonify({'result': result})
@app.route('/divide', methods=['POST'])
def divide():
data = request.get_json()
a = data['a']
b = data['b']
# Проверка деления на 0
if b == 0:
return jsonify({'error': 'Division by zero is not allowed'}), 400
result = a / b
return jsonify({'result': result})
if __name__ == '__main__':
app.run(port=5000)