From bdf61fbeab866767fcd756f0e2883ec1514397b5 Mon Sep 17 00:00:00 2001 From: ROHITH1709-byte <24bct140@kgcas.com> Date: Fri, 18 Oct 2024 19:34:37 +0530 Subject: [PATCH] Update app.py --- BMI Calculator (Flask)/app.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/BMI Calculator (Flask)/app.py b/BMI Calculator (Flask)/app.py index 5216000ee..50373f067 100644 --- a/BMI Calculator (Flask)/app.py +++ b/BMI Calculator (Flask)/app.py @@ -1,27 +1,28 @@ from flask import Flask, render_template, request -# declare the app +# Declare the app app = Flask(__name__) -# start an app route +# Start an app route @app.route("/") def main(): return render_template("index.html") - -# route for bmi calculation result -@app.route("/bmi", methods=["GET", "POST"]) +# Route for BMI calculation result +@app.route("/bmi", methods=["POST"]) def calculate(): try: w = float(request.form.get("weight")) h = float(request.form.get("height")) - if w and h: + if w > 0 and h > 0: bmi = round(w / ((h / 100) ** 2), 3) return render_template("index.html", bmi=bmi) - except ValueError as error: - error = "Please enter all the values" + else: + error = "Weight and height must be positive numbers." + return render_template("index.html", error=error) + except ValueError: + error = "Please enter valid numeric values." return render_template("index.html", error=error) - if __name__ == "__main__": app.run(debug=True)