-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.py
30 lines (25 loc) · 924 Bytes
/
bmi.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
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
bmi = None
message = None
if request.method == "POST" and 'weight' in request.form:
weight = float(request.form.get('weight'))
height = float(request.form.get('height'))
bmi = cal_bmi(weight, height)
message = classify_bmi(bmi)
return render_template('bmi_index.html', bmi=bmi, message=message)
def cal_bmi(weight, height):
# Convert height to meters and calculate BMI
return round(weight / ((height / 100) ** 2), 2)
def classify_bmi(bmi):
if bmi < 18.5:
return "You are underweight. Eat more."
elif 18.5 <= bmi < 24.9:
return "You are normal. Stay the same."
elif 25 <= bmi < 29.9:
return "You are overweight. Eat less."
else:
return "You are obese. Consult a doctor."
app.run(port = 5001)