Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# st.title("BMI CALCULATOR ")
|
| 3 |
+
# weight= st.user_input("Enter Your Weight (KG): ", min_value = 1.0,format= "%.2f")
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
# Set page title
|
| 7 |
+
st.title("BMI Calculator 🏋️♂️")
|
| 8 |
+
|
| 9 |
+
# User inputs for weight and height
|
| 10 |
+
weight = st.number_input("Enter your weight (kg):", min_value=1.0, format="%.2f")
|
| 11 |
+
|
| 12 |
+
height_unit = st.selectbox("Select height unit:", ["Centimeters", "Meters", "Feet"])
|
| 13 |
+
height = st.number_input("Enter your height:", min_value=1.0, format="%.2f")
|
| 14 |
+
|
| 15 |
+
# Convert height to meters
|
| 16 |
+
if height_unit == "Centimeters":
|
| 17 |
+
height = height / 100
|
| 18 |
+
elif height_unit == "Feet":
|
| 19 |
+
height = height * 0.3048 # Convert feet to meters
|
| 20 |
+
|
| 21 |
+
# BMI Calculation
|
| 22 |
+
if height > 0:
|
| 23 |
+
bmi = weight / (height ** 2)
|
| 24 |
+
st.write(f"### Your BMI: {bmi:.2f}")
|
| 25 |
+
|
| 26 |
+
# BMI Categories
|
| 27 |
+
if bmi < 18.5:
|
| 28 |
+
st.warning("You are underweight.")
|
| 29 |
+
elif 18.5 <= bmi < 24.9:
|
| 30 |
+
st.success("You have a normal weight.")
|
| 31 |
+
elif 25 <= bmi < 29.9:
|
| 32 |
+
st.warning("You are overweight.")
|
| 33 |
+
else:
|
| 34 |
+
st.error("You are in the obese category.")
|
| 35 |
+
else:
|
| 36 |
+
st.error("Please enter a valid height.")
|