Question: Overview In this project, you will create a program to calculate a person's caloric needs based on their age, sex, height, and weight. To do

Overview

In this project, you will create a program to calculate a person's caloric needs based on their age, sex, height, and weight. To do this, you will prompt the user for these inputs and use these values to calculate the person's body mass index (BMI) and a recommendation of caloric intake to achieve a healthy weight.

Objectives

Labs programs are focused in scope, concentrating on one, and maybe two, concepts. Projects are more comprehensive, requiring you to pull multiple concepts together into a workable solution. One of the main skills you should develop in this class, even more important than Python syntax and techniques, is to teach you to read a problem specification and put together the concepts required to solve it. This will also require you to be more deliberate in your thinking and in breaking the problem down into smaller, more manageable pieces. You will NOT be able to read this description through once and then start coding. It will require some planning first before you ever start banging away at code. In fact, 10% of your score on the project will be your use of writing pseudocode before you ever begin actual Python code.

The objective of this project is to create a solution combining multiple concepts that have been presented in class, demonstrating an understanding of:

inputting different types of data

outputting data according to specifications

using variables

using arithmetic expressions

using simple branching statements (if-else)

using nested branching statements and/or boolean operations

using code blocks and proper indentation

Note that you should only use techniques we have covered in class. Using more advanced concepts does not help your understanding of the basics, and is a red flag that the code may not be your own work. You will get docked points if you use constructs you were expressly told not to use. If you have questions about this as you work on your program, discuss them with the instructors during office hours.

Problem Description

Fictional health organization Healthy Spartans has tasked you with writing a simple program that can be used on their website that can help people calculate their caloric needs based on their physical attributes and levels of activity.

First, the program should prompt for whether physical attributes of age in years, sex (m/f), height in inches, weight in pounds, and a selection for how physically active they are. Note that height and weight in imperial units will need to be converted to metric for calculations, but the final message is using imperial units. The following table details the conversions:

Imperial Metric
1 inch (in) 2.54 centimeters (cm) or 0.0254 meters (m)
1 pound (lb) 0.454 kilograms (kg)

The purpose of this program is to print a statement that details how many calories a person would need to consume more than, equal to, or less than in order to gain weight, maintain weight, or lose weight, respectively. To determine this, the program will calculate BMI and categorize people as underweight, healthy, overweight, or obese, and the printed statement will reflect these categories. To calculate BMI, the following formula will be used:

BMI = (weight in kg)/(height in m)^2

A person's BMI will determine weight category according to the table below:

Range Weight Category
BMI < 18.5 underweight
18.5 BMI < 25 healthy
25 BMI < 30 overweight
BMI > 30 obese

To calculate the number of calories for this purpose, you will be using the following formulas:

For males: Calories required = ((13.397 * weight in kg) + (4.799 * height in cm) - (5.677 * age in years) + 88.362) * (physical activity factor)

For females: Calories required = ((9.247 * weight in kg) + (3.098 * height in cm) - (4.330 * age in years) + 447.593) * (physical activity factor)

Physical activity factor will be determined based on the table below:

Category Physical Activity Factor
Sedentary 1.2
Lightly Active 1.375
Moderately Active 1.55
Very Active 1.725
Extra Active 1.9

When the user runs the program, they should be presented with the prompt:

Enter your age in years: 

NOTE that this prompt and most prompts in your program should end with a colon and a newline.

In the event that the user enters any value that is less than 0, they should be given an error as follows:

ERROR: Age cannot be less than zero. 

and the program should end.

NOTE: Do not end your program by using break, exit, continue or similar constructs we have not covered. One of the goals of this project is to make sure you understand control flow using if statements, and if you can not write your program without using break or exit, you do not understand control flow well enough. Your score will be penalized if you use these constructs, even if your code passes all the test cases.

If provided a valid number, the program should proceed and print the following message, and prompt the user (you should have 3 lines total for the message and the input prompt):

If you identify as non-binary or something other than male or female, choose one of either "m" or "f" that you feel would be more accurate. Enter your sex (m/f): 

If the user enters anything that is not m or f, then the program should likewise give an error:

ERROR: Invalid sex. 

and the program should end.

If provided with a valid sex, the program should proceed and then prompt the user for height:

Enter your height in inches: 

and weight:

Enter your weight in pounds: 

Height and weight should be integers (whole numbers) without any fractional parts.

You may assume that the height and weight entered will be valid numbers and do not need to worry about checking whether the inputs are valid. In the real world you would want to check validity of all inputs, but in the interest of not having you nest your ifs too deeply, you do not need to error check height and weight for this project.

After the user has entered numbers for height and weight, the program should then proceed to prompt the user for their level of physical activity as follows:

Please select your physical activity on a weekly basis: 1. Sedentary (little or no exercise) 2. Lightly Active (light exercise/sports 1-3 days/week) 3. Moderately Active (moderate exercise/sports 3-5 days/week) 4. Very Active (hard exercise/sports 6-7 days/week) 5. Extra Active (very hard daily exercise/sports & physical job or 2X day training) 

Again, you do not have to check that the user entered something invalid; you can assume it will always be one of the given numbers. Hint: when getting the input for physical activity, since you have to print several lines, you may want to consider using standard print statements for the bulk of the instructions to the user, then using a promptless input statement to get the input itself. Or, you can use the final line as the prompt. Either way, note that there needs to be a newline before the user types anything in.

After the user has entered a valid selection for physical activity, the program should then perform the calculations necessary and output an appropriate message.

Example

Let's say that the user is a 20 year-old man who is 72 inches tall (6'0), 200 lbs, and is moderately active. In this case, his series of input prompts and the inputs would likely be:

Enter your age in years: 20 If you identify as non-binary or something other than male or female, choose one of either "m" or "f" that you feel would be more accurate. Enter your sex (m/f): m Enter your height in inches: 72 Enter your weight in pounds: 200 Please select your physical activity on a weekly basis: 1. Sedentary (little or no exercise) 2. Lightly Active (light exercise/sports 1-3 days/week) 3. Moderately Active (moderate exercise/sports 3-5 days/week) 4. Very Active (hard exercise/sports 6-7 days/week) 5. Extra Active (very hard daily exercise/sports & physical job or 2X day training) 3 

After providing these inputs, the man's BMI should then be calculated. He should have a BMI of (200 * 0.454)/(72 * (2.54/100))^2 = 27.149 and be considered overweight.

The number of calories he would require will also be calculated. The calories required should be ((13.397 * 200 * .454) + (4.799 * 72 * 2.54) - (5.677 * 20) + 88.362) * 1.55 = 3206.812 calories.

With these values calculated, we should expect an appropriate message of:

A 6'0 male weighing 200 lbs would have a BMI of 27.15 which is considered overweight. At 20 years old and being Moderately Active, you would require less than 3206.81 calories in order to lose weight. 

Other examples for when a person is underweight or at a healthy weight might be as follows:

A 5'5 female weighing 130 lbs would have a BMI of 21.65 which is considered healthy. At 20 years old and being Moderately Active, you would require about 2198.26 calories in order to maintain weight. 
A 5'6 male weighing 100 lbs would have a BMI of 16.15 which is considered underweight. At 20 years old and being Moderately Active, you would require more than 2150.70 calories in order to gain weight. 

So you will have slightly different messages depending on the sex of the person, their activity level, and their weight category. People who are under weight should intake more calories than the recommended in order to gain weight. People who are overweight or obese should intake less calories in order to lose weight. People who are at a healthy weight should intake the recommended calories to maintain weight.

Note that these are just examples of what might be input. You do not know what a user or the auto grader may input, and your program must work no matter what the input is. Some of the test cases are hidden, so you will not be able to see the input or output, but they will be like other visible test cases, so if you can pass the visible test cases but not the hidden ones, your program is likely doing something specific to the particular test cases.

Note the following in the printed statement:

Height is printed as feet and inches with an apostrophe separating the number of feet from the number of inches

The BMI has a precision of 2 decimal points

The number of calories has a precision of 2 decimal points

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!