Files
nutrition-calculator/bmi_calorie_calculator.py
class03f06 5b7048af0f 添加 BMI 与每日热量需求计算
- 按 15 岁女生、身高 1.62 m、体重 47 kg 计算 BMI
- 按每天约 1 万步的活动量计算每日热量需求
- 记录计算所用的公式与活动系数取值
2026-09-24 02:49:56 +00:00

81 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""BMI 与每日热量需求计算。
输入数据:
年龄:15 岁 性别:女
身高:1.62 m 体重:47 kg
日常活动:每天约 1 万步
计算与所用公式:
1) BMI = 体重(kg) / 身高(m)^2
2) 基础代谢 BMR(Mifflin-St Jeor,女性):
BMR = 10×体重 + 6.25×身高(cm) − 5×年龄 − 161
3) 活动系数 PAL(按每天步数估计):
<5000 → 1.2;5000-7499 → 1.4;7500-9999 → 1.5;
10000-12499 → 1.6;≥12500 → 1.8
4) 每日热量需求 = BMR × PAL
5) 交叉验证(EER,9-18 岁女生):
EER = 135.3 − 30.8×年龄 + PA×(10×体重 + 934×身高(m)) + 25
活跃档 PA = 1.31
"""
AGE = 15
SEX = "female"
HEIGHT_M = 1.62
WEIGHT_KG = 47
DAILY_STEPS = 10000
def calc_bmi(weight_kg, height_m):
"""BMI = 体重(kg) / 身高(m)^2"""
return weight_kg / height_m ** 2
def calc_bmr(weight_kg, height_m, age):
"""Mifflin-St Jeor 公式(女性),单位 kcal/天"""
return 10 * weight_kg + 6.25 * (height_m * 100) - 5 * age - 161
def pal_from_steps(steps):
"""按每天步数估计身体活动系数 PAL"""
if steps < 5000:
return 1.2
if steps < 7500:
return 1.4
if steps < 10000:
return 1.5
if steps < 12500:
return 1.6
return 1.8
def calc_tdee(bmr, pal):
"""每日热量需求 = BMR × PAL"""
return bmr * pal
def calc_eer(age, weight_kg, height_m, pa=1.31):
"""EER 公式(9-18 岁女生),pa 为活跃档 1.31"""
return 135.3 - 30.8 * age + pa * (10 * weight_kg + 934 * height_m) + 25
def main():
bmi = calc_bmi(WEIGHT_KG, HEIGHT_M)
bmr = calc_bmr(WEIGHT_KG, HEIGHT_M, AGE)
pal = pal_from_steps(DAILY_STEPS)
tdee = calc_tdee(bmr, pal)
eer = calc_eer(AGE, WEIGHT_KG, HEIGHT_M)
print("BMI 与每日热量需求计算")
print(f"输入:{AGE} 岁女生,{HEIGHT_M} m,{WEIGHT_KG} kg,每天约 {DAILY_STEPS} 步")
print(f"BMI : {bmi:.1f} kg/m²")
print(f"基础代谢 BMR : {bmr:.0f} kcal/天(Mifflin-St Jeor)")
print(f"活动系数 PAL : {pal}(按 {DAILY_STEPS} 步/天)")
print(f"每日热量需求 : {tdee:.0f} kcal/天(BMR × PAL)")
print(f"EER 交叉验证 : {eer:.0f} kcal/天(9-18 岁女生,活跃档)")
if __name__ == "__main__":
main()