Ashar086's picture
Update app.py
f2ea00e verified
raw
history blame
1.32 kB
import streamlit as st
st.title("BMI Calculator App")
# Input weight
weight = st.number_input("Enter your weight (in kgs)", min_value=0.0, step=0.1)
# Select height format
status = st.radio('Select your height format:', ('cms', 'meters', 'feet'))
# Input height based on selection
height = 0
if status == 'cms':
height = st.number_input('Enter height in Centimeters', min_value=0.0, step=0.1)
height /= 100 # Convert to meters
elif status == 'meters':
height = st.number_input('Enter height in Meters', min_value=0.0, step=0.01)
elif status == 'feet':
height = st.number_input('Enter height in Feet', min_value=0.0, step=0.1)
height /= 3.281 # Convert to meters
# BMI Calculation and Display
if st.button('Calculate BMI'):
if height > 0:
bmi = weight / (height ** 2)
st.text(f"Your BMI Index is {bmi:.2f}.")
# Categorizing BMI
if bmi < 16:
st.error("You are Extremely Underweight")
elif 16 <= bmi < 18.5:
st.warning("You are Underweight")
elif 18.5 <= bmi < 25:
st.success("You are Healthy")
elif 25 <= bmi < 30:
st.warning("You are Overweight")
else:
st.error("You are Extremely Overweight")
else:
st.error("Please enter a valid height greater than 0.")