マクロ栄養素計算機
カロリー目標に基づいて毎日のタンパク質・炭水化物・脂質量を計算。ケトジェニック・低炭水化物・カスタム比率対応。
タンパク質 30%炭水化物 40%脂質 30%
よくある質問
コード実装
def calculate_macros(calories, protein_pct, carbs_pct, fat_pct, meals=3):
"""
Calculate macronutrient grams from daily calorie goal.
Protein & carbs: 4 kcal/g, Fat: 9 kcal/g
"""
if abs(protein_pct + carbs_pct + fat_pct - 100) > 0.5:
raise ValueError("Percentages must add up to 100")
protein_kcal = calories * protein_pct / 100
carbs_kcal = calories * carbs_pct / 100
fat_kcal = calories * fat_pct / 100
protein_g = protein_kcal / 4
carbs_g = carbs_kcal / 4
fat_g = fat_kcal / 9
return {
"daily": {"protein": round(protein_g, 1), "carbs": round(carbs_g, 1), "fat": round(fat_g, 1)},
"per_meal": {"protein": round(protein_g / meals, 1),
"carbs": round(carbs_g / meals, 1),
"fat": round(fat_g / meals, 1)},
"calories": {"protein": round(protein_kcal), "carbs": round(carbs_kcal), "fat": round(fat_kcal)},
}
PRESETS = {
"balanced": (30, 40, 30),
"low_carb": (40, 20, 40),
"keto": (35, 5, 60),
"high_protein":(45, 35, 20),
}
# Example: 2000 kcal keto diet, 3 meals
result = calculate_macros(2000, *PRESETS["keto"], meals=3)
print("Daily macros:", result["daily"])
print("Per meal: ", result["per_meal"])Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.