This lab assignment will require you to write some basic programs in python. A skeleton version of each program that you will write will appear when you run update21. The program handin21 will only submit files in the current lab directory cs21/labs/01. Start by using cd to navigate to this directory.
Your programs are graded on both correctness and style. Please
review the comments regarding programming style on the main page.
Your Basal Metabolic Rate (BMR) is the amount of energy your body needs to function. We can estimate BMR based on height in inches, weight in pounds, age in years, and gender. Given your BMR we can then estimate the number of calories needed per day to maintain your weight.
For women: BMR = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age)
For men: BMR = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age)
Assuming that you are moderately active then multiply your BMR by 40% and add this to your BMR to get the appropriate number of calories to maintain your current weight.
For example, a program to calculate female BMRs should work as follows:
This program calculates Basal Metabolic Rate (BMR) for women. Enter height in inches: 65 Enter weight in pounds: 140 Enter age in years: 20 BMR: 1468.5 Calories needed to maintain weight: 2055.9
While a program to calculate male BMRs should work as follows:
This program calculates Basal Metabolic Rate (BMR) for men. Enter height in inches: 71 Enter weight in pounds: 165 Enter age in years: 18 BMR: 1899.0 Calories needed to maintain weight: 2658.6
Open the file bmr.py in the current lab directory and create
a main program that calculates BMR and calories needed to
maintain weight for either men or women, your choice. You don't need
to do both.
A joule is a unit of energy where 1 calorie is equal to 4.1868 joules. Open the file convertCalories.py in the current lab directory and create a main program that works as follows:
This program converts calories to joules. Enter starting calorie amount: 500 Enter ending calorie amount: 1000 Enter the step size: 50 Calories Joules 500 2093.4 550 2302.74 600 2512.08 650 2721.42 700 2930.76 750 3140.1 800 3349.44 850 3558.78 900 3768.12 950 3977.46 1000 4186.8
To get the values to line up in columns you can print out one or more tab characters ("\t") between printing the values on each line. For example, try these print statements in python and see what happens:
print 3, "\t\t", 4 print 3, "\t", 4
Here is another sample run of this program:
This program converts calories to joules. Enter starting calorie amount: 25 Enter ending calorie amount: 200 Enter the step size: 25 Calories Joules 25 104.67 50 209.34 75 314.01 100 418.68 125 523.35 150 628.02 175 732.69 200 837.36
Once you are satisfied with your programs, hand them in by typing handin21 at the unix prompt.
You may run handin21 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them.