Calculate Caloric Intake Learning Objective: In this lab, you will practice Functions and test functions Lists Printing If statements Instructions: Main Idea The Basal Metabolic Rate (BMR) is the amount of energy (calories) your body needs while resting. This accounts for about 60 to 70 percent of calories burned in a day. In general, men have a higher BMR than women. One of the most accurate methods of estimating your basal metabolic rate is the Harris-Benedict formula: Adult_Male_BMR = 66 + (6.3 x bodyweight in lbs.) + (12.9 x height in inches) - (6.8 x age in years) Adult_Female_BMR = 655 + (4.3 x weight in lbs.) + (4.7 x height in inches) - (4.7 x age in years) In this lab, you will be given the function calculate_calorie_intake and you will be required to write the body of the test functions test_calculate_calorie_intake_negative, test_calculate_calorie_intake_1, test_calculate_calorie_intake_3. In these functions, you will write function calls to calculate_calorie_intake and will check if the result matches the expected return or not. Steps In function test_calculate_calorie_intake_negative: call calculate_calorie_intake with BMR = 705 and activity_index= -1 If the expected result (should be zero) is equal to the result (the return of the function call), print: Test Passed. Otherwise, print: Test failed! Expected ---> Result In test_calculate_calorie_intake_1: call calculate_calorie_intake with BMR = 1076 and activity_index= 1 If the expected result (should be1478 ) is equal to the result (the return of the function call), print: Test Passed. Otherwise, print: Test failed! Expected ---> Result In test_calculate_calorie_intake_3: call calculate_calorie_intake with BMR = 1068 and activity_index= 3 If the expected result (should be 1655.4) is equal to the result (the return of the function call), print: Test Passed. Otherwise, print: Test failed! Expected ---> Result This is my wrong code below: def calculate_calorie_intake(BMR , activity_index): if activity_index == 1: return BMR * 1.2 elif activity_index == 2: return BMR * 1.375 elif activity_index == 3: return BMR * 1.55 elif activity_index == 4: return BMR * 1.725 elif activity_index == 5: return BMR * 1.9 else: return 0 def test_calculate_calorie_intake_negative(): print("Test: calculate_calorie_intake: activity index = -1") #Write your code here pass def test_calculate_calorie_intake_1(): print("Test: calculate_calorie_intake: activity index = 1") #Write your code here pass def test_calculate_calorie_intake_3(): print("Test: calculate_calorie_intake: activity index = 3") #write your code here pass if __name__ == "__main__": test_calculate_calorie_intake_negative() test_calculate_calorie_intake_1() test_calculate_calorie_intake_3()
Calculate Caloric Intake
Learning Objective:
In this lab, you will practice
- Functions and test functions
- Lists
- Printing
- If statements
Instructions:
Main Idea
The Basal Metabolic Rate (BMR) is the amount of energy (calories) your body needs while resting. This accounts for about 60 to 70 percent of calories burned in a day. In general, men have a higher BMR than women. One of the most accurate methods of estimating your basal metabolic rate is the Harris-Benedict formula:
Adult_Male_BMR = 66 + (6.3 x bodyweight in lbs.) + (12.9 x height in inches) - (6.8 x age in years)
Adult_Female_BMR = 655 + (4.3 x weight in lbs.) + (4.7 x height in inches) - (4.7 x age in years)
In this lab, you will be given the function calculate_calorie_intake and you will be required to write the body of the test functions test_calculate_calorie_intake_negative, test_calculate_calorie_intake_1, test_calculate_calorie_intake_3. In these functions, you will write function calls to calculate_calorie_intake and will check if the result matches the expected return or not.
Steps
-
In function test_calculate_calorie_intake_negative:
- call calculate_calorie_intake with BMR = 705 and activity_index= -1
- If the expected result (should be zero) is equal to the result (the return of the function call), print: Test Passed.
- Otherwise, print: Test failed! Expected <expected> ---> Result <result>
-
In test_calculate_calorie_intake_1:
- call calculate_calorie_intake with BMR = 1076 and activity_index= 1
- If the expected result (should be1478 ) is equal to the result (the return of the function call), print: Test Passed.
- Otherwise, print: Test failed! Expected <expected> ---> Result <result>
-
In test_calculate_calorie_intake_3:
- call calculate_calorie_intake with BMR = 1068 and activity_index= 3
- If the expected result (should be 1655.4) is equal to the result (the return of the function call), print: Test Passed.
- Otherwise, print: Test failed! Expected <expected> ---> Result <result>
This is my wrong code below:
def calculate_calorie_intake(BMR , activity_index):
if activity_index == 1:
return BMR * 1.2
elif activity_index == 2:
return BMR * 1.375
elif activity_index == 3:
return BMR * 1.55
elif activity_index == 4:
return BMR * 1.725
elif activity_index == 5:
return BMR * 1.9
else:
return 0
def test_calculate_calorie_intake_negative():
print("Test: calculate_calorie_intake: activity index = -1")
#Write your code here
pass
def test_calculate_calorie_intake_1():
print("Test: calculate_calorie_intake: activity index = 1")
#Write your code here
pass
def test_calculate_calorie_intake_3():
print("Test: calculate_calorie_intake: activity index = 3")
#write your code here
pass
if __name__ == "__main__":
test_calculate_calorie_intake_negative()
test_calculate_calorie_intake_1()
test_calculate_calorie_intake_3()
Step by step
Solved in 3 steps with 3 images