🛠️ToolsShed

다량영양소 계산기

칼로리 목표에 따라 단백질, 탄수화물, 지방 섭취량을 계산합니다. 균형식, 케토, 저탄수화물, 사용자 정의 비율 지원.

단백질 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.