Files
class03m15 e526e677cf 以 70 kg / 180 cm 为基准,按体脂率与每日最佳摄入热量新增每日营养方案计算
- 基准:体重 70 kg、身高 180 cm
- 体脂率未实测时按 Deurenberg 公式估算,并据此换算去脂体重
- 按活动量估算 TDEE,得出目标摄入热量
- 输出三大营养素每日克数与每日食物建议量
2026-09-24 02:39:39 +00:00

161 lines
5.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.
# -*- coding: utf-8 -*-
"""每日营养方案计算器
输入体重、身高、体脂率、年龄、性别、活动量和目标,输出:
* BMI 与体脂率(未实测时按 Deurenberg 公式估算)
* 基础代谢 BMR 与每日总消耗 TDEE
* 目标摄入热量
* 三大营养素每日建议量
* 每日食物建议量
用法:
python nutrition_plan.py
python nutrition_plan.py --weight 70 --height 180 --bodyfat 15.5 \\
--age 25 --sex male --activity light --goal maintain
"""
import argparse
# 活动系数
ACTIVITY = {
"sedentary": ("久坐(几乎不运动)", 1.2),
"light": ("轻度(每周训练 1-3 次)", 1.375),
"moderate": ("中度(每周训练 3-5 次)", 1.55),
"active": ("高度(每周训练 6-7 次)", 1.725),
}
# 目标:相对 TDEE 的热量调整比例
GOAL = {
"cut": ("减脂", -0.18),
"maintain": ("维持 / 身体重组", 0.0),
"bulk": ("增肌", 0.08),
}
# 以约 2300 kcal 为基准的每日食物建议量
BASE_KCAL = 2300.0
FOODS = [
("谷薯主食(生重)", "250-300 g", "全谷物 / 杂豆 ≥ 1/3"),
("禽畜肉 / 鱼虾", "250-350 g", "优先鸡胸、瘦牛、鱼虾贝类"),
("鸡蛋", "1-2 个", "约 50-100 g"),
("奶类", "300-500 ml", "牛奶或无糖酸奶"),
("豆制品", "100-150 g", "北豆腐 / 豆干 / 无糖豆浆"),
("蔬菜", "400-500 g", "深色蔬菜占一半"),
("水果", "200-350 g", "整个水果优于果汁"),
("坚果种子", "10-15 g", "原味无盐"),
("烹调油", "20-25 g", "多种植物油轮换"),
("盐", "≤ 5 g", "含酱油、蚝油等隐形盐"),
("膳食纤维", "30-35 g", "全谷、豆类、蔬果"),
("饮水", "2.5-3.5 L", "训练日再加 0.5-1 L"),
]
def bmi(weight_kg, height_cm):
h = height_cm / 100.0
return weight_kg / (h * h)
def bodyfat_deurenberg(bmi_value, age, sex):
"""未实测体脂率时按 Deurenberg 公式估算(男 sex=1,女 sex=0)"""
return 1.20 * bmi_value + 0.23 * age - 10.8 * sex - 5.4
def bmr_mifflin(weight_kg, height_cm, age, sex):
"""Mifflin-St Jeor 基础代谢(男 sex=1,女 sex=0)"""
return 10 * weight_kg + 6.25 * height_cm - 5 * age + (5 if sex == 1 else -161)
def bmr_katch(lean_kg):
"""Katch-McArdle 基础代谢,基于去脂体重"""
return 370 + 21.6 * lean_kg
def compute(args):
sex = 1 if args.sex == "male" else 0
b = bmi(args.weight, args.height)
estimated = args.bodyfat is None
bf = bodyfat_deurenberg(b, args.age, sex) if estimated else args.bodyfat
lean = args.weight * (1 - bf / 100.0)
bmr = (bmr_mifflin(args.weight, args.height, args.age, sex) + bmr_katch(lean)) / 2.0
tdee = bmr * ACTIVITY[args.activity][1]
target = tdee * (1 + GOAL[args.goal][1])
protein_g = 2.2 * lean # 2.2 g / kg 去脂体重
fat_g = 1.0 * args.weight # 1.0 g / kg 体重
carb_g = max(0.0, (target - protein_g * 4 - fat_g * 9) / 4.0)
return {
"bmi": b,
"bf": bf,
"estimated": estimated,
"lean": lean,
"bmr": bmr,
"tdee": tdee,
"target": target,
"protein_g": protein_g,
"fat_g": fat_g,
"carb_g": carb_g,
}
def report(args, r):
sex_label = "男" if args.sex == "male" else "女"
print("=" * 54)
print("每日营养方案")
print("=" * 54)
print(f"体重 {args.weight:.1f} kg 身高 {args.height:.1f} cm "
f"年龄 {args.age} 岁 {sex_label}性")
print(f"活动量:{ACTIVITY[args.activity][0]}")
print(f"目标:{GOAL[args.goal][0]}")
print("-" * 54)
print(f"BMI : {r['bmi']:.1f}")
print(f"体脂率({'估算' if r['estimated'] else '实测'}) : {r['bf']:.1f} %")
print(f"去脂体重 : {r['lean']:.1f} kg")
print(f"BMR : {r['bmr']:.0f} kcal")
print(f"TDEE : {r['tdee']:.0f} kcal")
print(f"目标摄入热量 : {r['target']:.0f} kcal")
print("-" * 54)
print("三大营养素")
rows = [
("蛋白质", r["protein_g"], 4),
("脂肪", r["fat_g"], 9),
("碳水化合物", r["carb_g"], 4),
]
total_kcal = sum(g * k for _, g, k in rows)
for name, grams, kcal_per_g in rows:
kcal = grams * kcal_per_g
print(f" {name:<5}: {grams:6.0f} g "
f"({kcal:5.0f} kcal, {kcal / total_kcal * 100:4.1f}%)")
scale = r["target"] / BASE_KCAL
print("-" * 54)
print(f"每日食物建议(基准 {BASE_KCAL:.0f} kcal,"
f"当前目标 ×{scale:.2f},按比例增减主食与肉蛋奶)")
for name, amount, note in FOODS:
print(f" {name:<12}: {amount:<12} {note}")
print("=" * 54)
def build_parser():
p = argparse.ArgumentParser(description="每日营养方案计算器")
p.add_argument("--weight", type=float, default=70.0, help="体重 kg")
p.add_argument("--height", type=float, default=180.0, help="身高 cm")
p.add_argument("--bodyfat", type=float, default=None, help="体脂率 %%,缺省则估算")
p.add_argument("--age", type=int, default=25, help="年龄")
p.add_argument("--sex", choices=["male", "female"], default="male")
p.add_argument("--activity", choices=list(ACTIVITY), default="light")
p.add_argument("--goal", choices=list(GOAL), default="maintain")
return p
def main():
args = build_parser().parse_args()
report(args, compute(args))
if __name__ == "__main__":
main()