Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| # Page settings | |
| st.set_page_config(page_title="BMI Calculator", layout="centered") | |
| st.title("💪 BMI Calculator") | |
| st.subheader("Check your Body Mass Index") | |
| # Input fields | |
| height = st.number_input("Enter your height (in cm):", min_value=50, max_value=250, step=1) | |
| weight = st.number_input("Enter your weight (in kg):", min_value=10, max_value=300, step=1) | |
| # BMI calculation | |
| if st.button("Calculate BMI"): | |
| if height == 0: | |
| st.error("Height must be greater than 0.") | |
| else: | |
| height_m = height / 100 # Convert to meters | |
| bmi = weight / (height_m ** 2) | |
| st.success(f"Your BMI is: **{bmi:.2f}**") | |
| # BMI category | |
| if bmi < 18.5: | |
| st.info("💡 You are **Underweight**.") | |
| elif 18.5 <= bmi < 24.9: | |
| st.success("✅ You have a **Normal** weight.") | |
| elif 25 <= bmi < 29.9: | |
| st.warning("⚠️ You are **Overweight**.") | |
| else: | |
| st.error("❌ You are **Obese**.") | |