Body Age Calculator
Estimate your biological body age based on BMI, blood pressure, exercise habits, and lifestyle factors.
LowHigh
Questions Fréquentes
Implémentation du Code
def calculate_body_age(
chronological_age: int,
bmi: float,
systolic_bp: int,
resting_hr: int,
weekly_exercise_hours: float,
smoking: bool,
sleep_hours: float,
stress_level: int # 1-10
) -> dict:
"""
Estimate biological age based on lifestyle factors.
Returns body age and adjustments.
"""
body_age = chronological_age
adjustments = []
# BMI impact (optimal 18.5-24.9)
if bmi < 18.5:
body_age += 1
adjustments.append("Underweight (+1 year)")
elif 25 <= bmi < 30:
body_age += 2
adjustments.append("Overweight (+2 years)")
elif bmi >= 30:
body_age += 5
adjustments.append("Obese (+5 years)")
# Blood pressure (optimal < 120/80)
if systolic_bp >= 140:
body_age += 5
adjustments.append("High blood pressure (+5 years)")
elif systolic_bp >= 120:
body_age += 2
adjustments.append("Elevated BP (+2 years)")
# Resting heart rate (optimal 50-70)
if resting_hr < 60:
body_age -= 2
adjustments.append("Low resting HR (-2 years)")
elif resting_hr > 90:
body_age += 4
adjustments.append("High resting HR (+4 years)")
elif resting_hr > 75:
body_age += 2
adjustments.append("Slightly high HR (+2 years)")
# Exercise (optimal 5+ hours/week)
if weekly_exercise_hours >= 5:
body_age -= 4
adjustments.append("Active lifestyle (-4 years)")
elif weekly_exercise_hours >= 2.5:
body_age -= 2
adjustments.append("Moderate exercise (-2 years)")
elif weekly_exercise_hours < 1:
body_age += 3
adjustments.append("Sedentary (+3 years)")
# Smoking
if smoking:
body_age += 8
adjustments.append("Smoking (+8 years)")
# Sleep (optimal 7-9 hours)
if sleep_hours < 6 or sleep_hours > 9:
body_age += 2
adjustments.append("Poor sleep (+2 years)")
# Stress (optimal 1-3)
if stress_level >= 7:
body_age += 3
adjustments.append("High stress (+3 years)")
elif stress_level >= 5:
body_age += 1
adjustments.append("Moderate stress (+1 year)")
return {
"chronological_age": chronological_age,
"body_age": max(chronological_age - 15, body_age),
"difference": body_age - chronological_age,
"adjustments": adjustments
}
result = calculate_body_age(
chronological_age=35, bmi=22.5, systolic_bp=115,
resting_hr=62, weekly_exercise_hours=4, smoking=False,
sleep_hours=7.5, stress_level=4
)
print(f"Chronological age: {result['chronological_age']}")
print(f"Body age: {result['body_age']}")
print(f"Difference: {result['difference']:+d} years")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.