-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from ROHITH1709-byte/patch-1
Update app.py
- Loading branch information
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |