From d1ed9681fe89f1a72b057e22164fcd7848b7a2af Mon Sep 17 00:00:00 2001 From: PreedhiVivek Date: Wed, 25 Sep 2019 14:15:06 +0530 Subject: [PATCH 1/3] Flask application to calculate the BMI of the user --- bmi_calculator.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bmi_calculator.py diff --git a/bmi_calculator.py b/bmi_calculator.py new file mode 100644 index 0000000..2e75d7f --- /dev/null +++ b/bmi_calculator.py @@ -0,0 +1,35 @@ +""" +Purpose: +A Flask application to calculate the BMI of the user. + +""" + +from flask import Flask, jsonify, render_template, request + +app = Flask(__name__) + +def calculate_bmi(weight_of_the_user,height_of_the_user): + # Calculate the BMI of the user according to height and weight + bmi_of_the_user = round(weight_of_the_user/(height_of_the_user * height_of_the_user),1) + return bmi_of_the_user + +@app.route("/", methods=['GET', 'POST']) +@app.route("/bmi", methods=['GET', 'POST']) +def bmi(): + "Endpoint for calculating the bmi of a user" + if request.method == 'GET': + #return the form + return render_template('bmi.html') + if request.method == 'POST': + #return the answer + weight = float(request.form.get('weight')) + height = float(request.form.get('height')) + + result = calculate_bmi(weight,height) + api_response = {"answer": result} + return jsonify(api_response) + + +#---START OF SCRIPT +if __name__ == '__main__': + app.run(host='0.0.0.0', port=6464, debug= True) \ No newline at end of file From e34c1b0b1a9d773538e760274a9d65bebbdc76b6 Mon Sep 17 00:00:00 2001 From: PreedhiVivek Date: Wed, 25 Sep 2019 14:16:02 +0530 Subject: [PATCH 2/3] Stylesheet for BMI flask application --- static/css/bmi_style.css | 127 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 static/css/bmi_style.css diff --git a/static/css/bmi_style.css b/static/css/bmi_style.css new file mode 100644 index 0000000..7cd6211 --- /dev/null +++ b/static/css/bmi_style.css @@ -0,0 +1,127 @@ +/*Stylesheet for BMI Calculator application*/ + +body { + padding-top: 40px; + font-size: 16px; + font-family: "Open Sans",serif; + background-color:antiquewhite; +} + +h1 { + font-family: "Abel", Arial, sans-serif; + font-weight: 400; + font-size: 40px; + color:#5cb85cff; + line-height: 1.0; +} + +h2 { + font-family: "Abel", Arial, sans-serif; +} + +h3 { + font-family: "Abel", Arial, sans-serif; +} + +p { + line-height: 2.0; +} + +li { + line-height: 2.0; +} + + +/* Override B3 .panel adding a subtly transparent background */ +.panel { + background-color: rgba(255, 255, 255, 0.9); +} + +.toppy { + padding-top: 70px; +} + +.comment { + /* Src: http://codepen.io/martinwolf/pen/qlFdp */ + display: block; /* Fallback for non-webkit */ + display: -webkit-box; + margin: 0 auto; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; +} + +.p_result{ + line-height: 1.8; +} + +.margin-base-vertical { + margin: 40px 0; +} + +.wor_copyright { + font-family: "Abel", Arial, sans-serif; + font-size: 12px; +} + + +/*Add vertical space above divs*/ +.top-space-5 { + margin-top:5px; +} + +.top-space-10 { + margin-top:10px; +} + +.top-space { + margin-top:10px; +} + +.top-space-15 { + margin-top:15px; +} + +.top-space-20 { + margin-top:20px; +} + +.top-space-25 { + margin-top:25px; +} + +.top-space-30 { + margin-top:30px; +} + +.top-space-40 { + margin-top:40px; +} + +.top-space-50 { + margin-top:50px; +} + +/*Logo*/ +img.logo{ + max-height: 100px; + max-width: 250px; +} + +grey-text { + color: #7e7e7e; + margin-top: 5px; +} + +.toppy-10 { + padding-top: 10px; +} + +.toppy-20 { + padding-top: 20px; +} + +.toppy-30 { + padding-top: 30px; +} From 9c278c80e3be31606244aa60660bf6a82e26c3a1 Mon Sep 17 00:00:00 2001 From: PreedhiVivek Date: Wed, 25 Sep 2019 14:16:41 +0530 Subject: [PATCH 3/3] HTML webpage for BMI Calculator --- templates/bmi.html | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 templates/bmi.html diff --git a/templates/bmi.html b/templates/bmi.html new file mode 100644 index 0000000..6b70724 --- /dev/null +++ b/templates/bmi.html @@ -0,0 +1,99 @@ + + + + + + + BMI + + + + + + + + + + + + +
+
+
+

BMI calculator!

+

+ + + + +

+

+ + + + +

+

+ +

+
+
+
+
+

+

+
+
+
+ + + + \ No newline at end of file