Почти всё дописано, коммит для того, чтобы выделить ветку

This commit is contained in:
dr_domi
2026-05-02 21:43:38 +03:00
parent e0fb94d299
commit d9e05ea8e0
3 changed files with 199 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
from flask import Flask, request, jsonify, render_template
app = Flask(__name__)
def calculate_bmi(height, weight):
return round(weight / (height ** 2), 2)
def user_input_check(height, weight):
if height <= 0 or height > 3:
return "Рост должен быть больше 0 и не превышать 3 метра."
if weight <= 0 or weight > 200:
return "Вес должен быть больше 0 и не превышать 200 кг."
return None
@app.route('/')
def index():
return render_template('index.html')
@app.route('/calculate', methods=['POST'])
def calculate():
data = request.get_json()
height = float(data['height'])
weight = float(data['weight'])
error = user_input_check(height, weight)
if error:
return jsonify({'error': error}), 400
bmi = calculate_bmi(height, weight)
return jsonify({'bmi': bmi})
if __name__ == '__main__':
app.run(debug=True)