Skip to content

Commit

Permalink
Merge pull request #628 from ROHITH1709-byte/patch-1
Browse files Browse the repository at this point in the history
Update app.py
  • Loading branch information
Ayushparikh-code authored Oct 29, 2024
2 parents c8c8c17 + bdf61fb commit 797dd59
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions BMI Calculator (Flask)/app.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 797dd59

Please sign in to comment.