Calcolatore Macronutrienti
Calcola i tuoi obiettivi giornalieri di proteine, carboidrati e grassi in base al tuo obiettivo calorico. Supporta diete equilibrate, keto, low carb e personalizzate.
Protein 30%Carbohydrates 40%Fat 30%
Domande Frequenti
Implementazione del Codice
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.