Skip to content

Commit 797dd59

Browse files
Merge pull request #628 from ROHITH1709-byte/patch-1
Update app.py
2 parents c8c8c17 + bdf61fb commit 797dd59

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

BMI Calculator (Flask)/app.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
from flask import Flask, render_template, request
22

3-
# declare the app
3+
# Declare the app
44
app = Flask(__name__)
55

6-
# start an app route
6+
# Start an app route
77
@app.route("/")
88
def main():
99
return render_template("index.html")
1010

11-
12-
# route for bmi calculation result
13-
@app.route("/bmi", methods=["GET", "POST"])
11+
# Route for BMI calculation result
12+
@app.route("/bmi", methods=["POST"])
1413
def calculate():
1514
try:
1615
w = float(request.form.get("weight"))
1716
h = float(request.form.get("height"))
18-
if w and h:
17+
if w > 0 and h > 0:
1918
bmi = round(w / ((h / 100) ** 2), 3)
2019
return render_template("index.html", bmi=bmi)
21-
except ValueError as error:
22-
error = "Please enter all the values"
20+
else:
21+
error = "Weight and height must be positive numbers."
22+
return render_template("index.html", error=error)
23+
except ValueError:
24+
error = "Please enter valid numeric values."
2325
return render_template("index.html", error=error)
2426

25-
2627
if __name__ == "__main__":
2728
app.run(debug=True)

0 commit comments

Comments
 (0)