Python Program to Calculate Daily Calorie Intake for Weight Maintenance
Here's the Python code for the helper functions:
def female_bmr(weight, height, age):
'''
Calculates the Basal Metabolic Rate (BMR) for a female.
Args:
weight (float): Weight in kilograms.
height (float): Height in centimeters.
age (int): Age in years.
Returns:
float: BMR for a female.
'''
return 447.593 + (3.247 * weight) + (3.096 * height) - (4.33 * age)
def male_bmr(weight, height, age):
'''
Calculates the Basal Metabolic Rate (BMR) for a male.
Args:
weight (float): Weight in kilograms.
height (float): Height in centimeters.
age (int): Age in years.
Returns:
float: BMR for a male.
'''
return 88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age)
def calculate_daily_calorie_intake(weight, height, age, gender, exercise_level):
'''
Calculates the total recommended daily calorie intake needed to maintain current weight.
Args:
weight (float): Weight in kilograms.
height (float): Height in centimeters.
age (int): Age in years.
gender (int): 0 for female, 1 for male.
exercise_level (int): 0 for no exercise, 1 for light exercise, 2 for moderate exercise, 3 for heavy exercise.
Returns:
float: Total recommended daily calorie intake.
'''
if gender == 0:
bmr = female_bmr(weight, height, age)
else:
bmr = male_bmr(weight, height, age)
if exercise_level == 0:
return bmr * 1.2
elif exercise_level == 1:
return bmr * 1.375
elif exercise_level == 2:
return bmr * 1.55
elif exercise_level == 3:
return bmr * 1.725
You can use the calculate_daily_calorie_intake function to calculate the recommended daily calorie intake based on the inputs of weight, height, age, gender, and exercise level. The function will return the total recommended daily calorie intake.
原文地址: https://www.cveoy.top/t/topic/lTjO 著作权归作者所有。请勿转载和采集!