Почти всё дописано, коммит для того, чтобы выделить ветку
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user