A good diet is an integral aspect of a balanced lifestyle. It defines the well-being of a human being. Nutrients are divided into two categories i.e macronutrients and micronutrients. Macronutrients are the nutrition that the body needs a large amount. Macronutrients provide calories or energy on the other hand micronutrients are those nutrients that the body requires in smaller doses like Calcium, Potassium, Sodium, Iron, Zinc, etc.
In this article, we are going to write python scripts to get Macronutrient information from the given data.
We are going to use the fitness_tools module to calculate Macronutrient compounds. The goal of this package is to automate these calculations so you can spend more time following through with your nutrition plan.
Installation:
pip install fitness-tools
Let’s understand this module with implementation:
The make_meal() class method returns a dictionary of recommended calories and macronutrients for a meal based on your input and passing int through the function.
Syntax:
fitness_tools.meals.meal_maker.MakeMeal(weight, goal=None, body_type=None, activity_level=None, min_cal=None, max_cal=None, fat_percent=None, protein_percent=None, carb_percent=None)
Parameters:
- weight: Enter your current weight.
- goal: Select a goal, ‘weight_loss’, ‘maintenance’, ‘weight_gain’, or None.
- body_type: Select a body type: ‘endomorph’, ‘ectomorph’, ‘mesomorph’ or None.
- activity_level: Select an activity level, ‘sedentary’, ‘moderate’, ‘very’,
or None.- min_cal: Enter the desired minimum calories per pound defaults to None.
- max_cal: Enter the desired maximum calories per pound defaults to None.
- fat_percent: Enter the desired percent of calories from fat defaults to None.
- protein_percent: Enter the desired percent of calories from protein defaults
to None.- carb_percent: Enter the desired percent of calories from carbohydrates
defaults to None.
Below are some programs which implement the use fitness_tools module for Macronutrient analysis:
Example 1:
Get the Macronutrient with daily_requirements() method.
Python3
# Import required modulesfrom fitness_tools.meals.meal_maker import MakeMeal # Create objectobj = MakeMeal(160, goal='weight_gain', activity_level='moderate', body_type='mesomorph') # Call required methodobj.daily_requirements() |
Output:

Example 2:
Python3
# Import required modulefrom fitness_tools.meals.meal_maker import MakeMeal # Create objectobj = MakeMeal(160, goal='weight_gain', activity_level='moderate', body_type='mesomorph') # Traverse each objectprint(obj.daily_max_calories())print(obj.daily_min_fat())print(obj.daily_max_protein())print(obj.daily_min_carbs())print(obj.daily_max_carbs()) # Return calories and macronutrients# for one meal.print(obj.make_meal(4)) |
Output:

Example 3:
Get macronutrient percentages and calorie ranges manually.
Python3
# Import required modulefrom fitness_tools.meals.meal_maker import MakeMeal # Create objectobj = MakeMeal(160, min_cal=10, max_cal=15, fat_percent=0.1, protein_percent=0.75, carb_percent=0.15) # returns calories, fat, protein,# and carbs in grams for one dayobj.daily_requirements() |
Output:

Note: The sum of fat_percent(), protein_percent(), and carb_percent() must be equal to 1.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


