Here are two simple Python scripts that will calculate the daily caloric intake for a human based on their gender, age, weight, height, and activity level using the Harris-Benedict equation:
Metric System of Measurement
def calculate_caloric_intake(gender, age, weight, height, activity_level):
if gender == 'male':
bmr = 88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age)
elif gender == 'female':
bmr = 447.593 + (9.247 * weight) + (3.098 * height) - (4.330 * age)
else:
raise ValueError("Invalid gender. Please enter 'male' or 'female'.")
activity_factors = {
'sedentary': 1.2,
'lightly active': 1.375,
'moderately active': 1.55,
'very active': 1.725,
'extra active': 1.9
}
if activity_level not in activity_factors:
raise ValueError("Invalid activity level.")
total_caloric_intake = bmr * activity_factors[activity_level]
return total_caloric_intake
# Example usage
gender = input("Enter your gender (male/female): ")
age = int(input("Enter your age: "))
weight = float(input("Enter your weight in kilograms: "))
height = float(input("Enter your height in centimeters: "))
activity_level = input("Enter your activity level (sedentary/lightly active/moderately active/very active/extra active): ")
caloric_intake = calculate_caloric_intake(gender, age, weight, height, activity_level)
print("Your daily caloric intake is:", caloric_intake)
Imperial System of Measurement
def calculate_caloric_intake(gender, age, weight, height, activity_level):
if gender == 'male':
weight_kg = weight * 0.453592 # Convert pounds to kilograms
height_cm = height * 2.54 # Convert inches to centimeters
bmr = 88.362 + (13.397 * weight_kg) + (4.799 * height_cm) - (5.677 * age)
elif gender == 'female':
weight_kg = weight * 0.453592 # Convert pounds to kilograms
height_cm = height * 2.54 # Convert inches to centimeters
bmr = 447.593 + (9.247 * weight_kg) + (3.098 * height_cm) - (4.330 * age)
else:
raise ValueError("Invalid gender. Please enter 'male' or 'female'.")
activity_factors = {
'sedentary': 1.2,
'lightly active': 1.375,
'moderately active': 1.55,
'very active': 1.725,
'extra active': 1.9
}
if activity_level not in activity_factors:
raise ValueError("Invalid activity level.")
total_caloric_intake = bmr * activity_factors[activity_level]
return total_caloric_intake
# Example usage
gender = input("Enter your gender (male/female): ")
age = int(input("Enter your age: "))
weight = float(input("Enter your weight in pounds: "))
height = float(input("Enter your height in inches: "))
activity_level = input("Enter your activity level (sedentary/lightly active/moderately active/very active/extra active): ")
caloric_intake = calculate_caloric_intake(gender, age, weight, height, activity_level)
print("Your daily caloric intake is:", caloric_intake)