使用Python中的 Fitness-Tools 模块进行常量营养素分析
良好的饮食习惯是平衡生活方式的一个组成部分。它定义了一个人的福祉。营养素分为两大类,即常量营养素和微量营养素。宏量营养素是人体需要大量的营养。宏量营养素提供卡路里或能量,而微量营养素是人体需要的小剂量营养素,如钙、钾、钠、铁、锌等。
在本文中,我们将编写Python脚本以从给定数据中获取宏量营养素信息。
我们将使用Fitness_tools模块来计算常量营养素化合物。该软件包的目标是使这些计算自动化,以便您可以花更多时间来执行您的营养计划。
安装:
pip install fitness-tools
让我们通过实现来理解这个模块:
make_meal() class 方法根据您的输入并通过函数传递 int 返回推荐卡路里和宏量营养素的字典。
句法:
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.
下面是一些实现使用 fitness_tools 模块进行宏量营养素分析的程序:
示例 1:
使用daily_requirements()方法获取常量营养素。
Python3
# Import required modules
from fitness_tools.meals.meal_maker import MakeMeal
# Create object
obj = MakeMeal(160, goal='weight_gain', activity_level='moderate',
body_type='mesomorph')
# Call required method
obj.daily_requirements()
Python3
# Import required module
from fitness_tools.meals.meal_maker import MakeMeal
# Create object
obj = MakeMeal(160, goal='weight_gain', activity_level='moderate',
body_type='mesomorph')
# Traverse each object
print(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))
Python3
# Import required module
from fitness_tools.meals.meal_maker import MakeMeal
# Create object
obj = 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 day
obj.daily_requirements()
输出:
示例 2:
蟒蛇3
# Import required module
from fitness_tools.meals.meal_maker import MakeMeal
# Create object
obj = MakeMeal(160, goal='weight_gain', activity_level='moderate',
body_type='mesomorph')
# Traverse each object
print(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))
输出:
示例 3:
手动获取常量营养素百分比和卡路里范围。
蟒蛇3
# Import required module
from fitness_tools.meals.meal_maker import MakeMeal
# Create object
obj = 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 day
obj.daily_requirements()
输出:
注意: fat_percent()、protein_percent()和carb_percent()的总和必须等于 1。