So Today we will be creating a good-looking BMI Calculator Web application. Before diving into this mini-project, We must know what is BMI.
What is BMI ?
Body Mass Index (BMI) is a person’s weight in kilograms divided by the square of height in meters. A high BMI can indicate high body fatness. BMI screens for weight categories that may lead to health problems, but it does not diagnose the body fatness or health of an individual.
Formulae to calculate BMI
BMI = Weight(kgs)/Height(metres) ²
How to know Status of Your Health ?
You are Underweight if your BMI is equal to or less than 18.5.
You are Normal Weight if your BMI lies within 18.5 to 24.9.
You are Over Weight if your BMI lies with 25 to 29.9
You are Obese if your BMI is greater than 29.9
Start Project
To Create a Web application, I will be using one of the awesome python framework Streamlit. So let’s start with this mini – project.
Step 1 – Install Streamlit
Go to Terminal and type
pip install streamlit
Now, You are good to go.
Import streamlit
To use Streamlit, First thing you need to do is import it.
import streamlit as st
Adding title of Web Application.
We will be using title function of streamlit to add the title of web application.
st.title('BMI Calculator')
Let’s Run our Web – application
To run a Web application, go to your terminal and type the following.
streamlit run filename.py
Your Application Would look something like this:
Asking User for Height and Weight :
To take values in number from user , we will simply use number input method of streamlit.
height = st.number_input('Please Enter Your Height in Cms : ',100,300 )
weight = st.number_input('Please Enter Your Weight in Kgs : ' )
To Calculate BMI :
Formulae to Calculate BMI is : weight/height/height*10000
bmi = round(height/weight/weight*10000,2)
Finalizing this mini project by checking BMI
Now to Check BMI , We will Compare bmi with formulae Criteria :
import streamlit as st
st.title('BMI Calculator')
height = st.number_input('Please Enter Your Height in Cms : ',100,300 )
weight = st.number_input('Please Enter Your Weight in Kgs : ',1 )
check = st.button('Find BMI')
if(check):
bmi = round(weight/height/height*10000,2)
st.title(f'Your BMI : {bmi}')
if(bmi>30):
st.title('You are Obese.')
elif(bmi>25):
st.title('You are Overweight.')
elif(bmi>18.5):
st.title('You are Normal Weight.')
else:
st.title('You are Underweight.')
Result :
Using Streamlit , you can build these kinds of simple web applications. But Streamlit offers much more than that if combined with data analysis . Streamlit can build highly complex data-driven useful web application. To learn Data analysis with python, you can enroll in our consoleflare course. and to know more reach out to me here . Good day.
Hiya! I just wish to give an enormous thumbs up for the nice info you’ve here on this post. I shall be coming back to your weblog for extra soon.