diff --git a/BMI Calculator/README.md b/BMI Calculator/README.md new file mode 100644 index 0000000000..768c96b0be --- /dev/null +++ b/BMI Calculator/README.md @@ -0,0 +1,22 @@ +# BMI Calculator Project + +This is a simple BMI (Body Mass Index) Calculator web application built using Python and Flask. It allows users to calculate their BMI based on their weight and height, and it provides an interpretation of the BMI category. + +## Project Structure + +The project consists of the following files: + +- `app.py`: This is the main Python script that contains the Flask application. It handles the server-side calculations and serves the web pages. +- `templates/`: This folder contains the HTML templates used for rendering the user interface. It includes two templates: + - `index.html`: The main page of the BMI calculator where users can enter their weight and height. + - `result.html`: The result page that displays the calculated BMI, its interpretation, and additional information about BMI categories. +- `styles.css`: The CSS file responsible for styling the user interface of the BMI calculator. + +## BMI Categories + +The BMI calculator provides interpretation for BMI categories as follows: + +- Underweight: less than 18.5 +- Normal weight: 18.5 - 24.9 +- Overweight: 25 - 29.9 +- Obese: 30 or greater \ No newline at end of file diff --git a/BMI Calculator/app.py b/BMI Calculator/app.py new file mode 100644 index 0000000000..09ae3c3c5b --- /dev/null +++ b/BMI Calculator/app.py @@ -0,0 +1,34 @@ +from flask import Flask, render_template, request + +app = Flask(__name__) + +def calculate_bmi(weight, height): + height_in_meters = height / 100 + bmi = weight / (height_in_meters ** 2) + return bmi + +def interpret_bmi(bmi): + if bmi < 18.5: + return "Underweight" + elif 18.5 <= bmi < 24.9: + return "Normal weight" + elif 25 <= bmi < 29.9: + return "Overweight" + else: + return "Obese" + +@app.route("/", methods=["GET", "POST"]) +def index(): + if request.method == "POST": + weight = float(request.form["weight"]) + height = float(request.form["height"]) + + bmi = calculate_bmi(weight, height) + interpretation = interpret_bmi(bmi) + + return render_template("result.html", bmi=bmi, interpretation=interpretation) + + return render_template("index.html") + +if __name__ == "__main__": + app.run(debug=True) diff --git a/BMI Calculator/styles.css b/BMI Calculator/styles.css new file mode 100644 index 0000000000..e63640cfea --- /dev/null +++ b/BMI Calculator/styles.css @@ -0,0 +1,54 @@ +body { + font-family: Arial, sans-serif; + background-color: #f8f8f8; + margin: 0; + padding: 0; +} + +.container { + max-width: 400px; + margin: 30px auto; + padding: 20px; + border: 1px solid #ccc; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + background-color: #fff; +} + +h1 { + text-align: center; +} + +label { + display: block; + margin-bottom: 5px; +} + +input { + width: 100%; + padding: 8px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 4px; +} + +input[type="submit"] { + background-color: #4CAF50; + color: #fff; + cursor: pointer; +} + +input[type="submit"]:hover { + background-color: #45a049; +} + +a { + display: block; + text-align: center; + color: #007bff; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} diff --git a/BMI Calculator/templates/index.html b/BMI Calculator/templates/index.html new file mode 100644 index 0000000000..aef4faf266 --- /dev/null +++ b/BMI Calculator/templates/index.html @@ -0,0 +1,22 @@ + + +
++ Welcome to the BMI Calculator! Enter your weight and height below to calculate your Body Mass Index (BMI). +
+ +Your BMI is: {{ bmi }}
+Interpretation: {{ interpretation }}
++ BMI Categories: +