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()
![1: Compare output a
Output differs. See highlights below.
Special character legend
Test: calculate_calorie_intake: activity index = -1
Your output
Test: calculate_calorie_intake: activity index = 1
Test: calculate_calorie_intake: activity index = 3
Test: calculate calorie intake: activity index = -1
Test Passede
Test: calculate_calorie_intake: activity index = 1
Expected output
Test failed! Expected 1478 ---> Result 1291.24
Test: calculate calorie intake: activity index = 3
Test Passedd](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F65d4b7c1-bff9-4699-bca1-37915a859545%2Fcd54b7b6-aa68-434c-8b65-d45832f433a3%2Fu2ckuml_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)