-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
website using html css and python flask #2676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
avinashkranjan
merged 1 commit into
avinashkranjan:master
from
Swapnil-2503:BMI-Calculator-Web
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -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 |
This file contains hidden or 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 |
---|---|---|
@@ -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) | ||
This file contains hidden or 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 |
---|---|---|
@@ -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; | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>BMI Calculator</title> | ||
<link rel="stylesheet" href="../styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>BMI Calculator</h1> | ||
<p> | ||
Welcome to the BMI Calculator! Enter your weight and height below to calculate your Body Mass Index (BMI). | ||
</p> | ||
<form method="post" action="/"> | ||
<label for="weight">Weight (kg):</label> | ||
<input type="number" step="0.01" name="weight" required><br> | ||
<label for="height">Height (cm):</label> | ||
<input type="number" step="0.01" name="height" required><br> | ||
<input type="submit" value="Calculate"> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>BMI Calculator - Result</title> | ||
<link rel="stylesheet" href="../styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Result</h1> | ||
<p>Your BMI is: {{ bmi }}</p> | ||
<p>Interpretation: {{ interpretation }}</p> | ||
<p> | ||
BMI Categories: | ||
<ul> | ||
<li>Underweight: less than 18.5</li> | ||
<li>Normal weight: 18.5 - 24.9</li> | ||
<li>Overweight: 25 - 29.9</li> | ||
<li>Obese: 30 or greater</li> | ||
</ul> | ||
</p> | ||
<a href="/">Calculate Again</a> | ||
</div> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Flask app is run in debug mode