bmi calculation

Posted 11 March 2010 - 07:49 PM

I was wondering if my code is written correctly. Here is the description of what I am supposed to do:

1.
You have to use a while loop to allow the user to run up to 3 BMI calculations. If
they decide to quit before by entering the letter 'q' for 'quit', they should be allowed
to quit the program. In all other cases (i.e. any other input) let them continue with the next BMI calculation. However, after 3 calculations the program should terminate.

2. If a weight < 0 or weight > 500 lbs is entered by the user, a specific helpful error message is
displayed and the program bypasses all other code (i.e., no computation or result display)
and goes back to the very beginning where the message “Program computes your BMI” is printed.
(See the sample program bmi1.py on the second page.)

3. If a height < 0 is entered another specific error message is displayed and the program bypasses
all other code and goes back to the very beginning where the message “Program computes your
BMI” is printed.

4. Based on the BMI value you compute, use the table provided on the Web site to display
if the person is underweight, normal weight, etc. (hint: sent this BMI value to a function to
determine the correct message to display and have it display it there.)

5. As part of your implementation, use functions and limit code duplication where possible. For
example, you will have a method named main, and in it you will have your main loop with the
if‐statements needed for error checking. Try not to fill up your main loop with lots of code, try to call methods instead if possible.

All I want to know is if I am supposed to have the program prompt the user to type in 'q'
after each calculation or just have all 3 calculations calculate one after the other and
after the 3rd calculation the program executes. If someone can interpret #1 for me at the
top that would be great. Here is the complete code I have written:

Re: bmi calculation

If it was me, I would put all the prompts in a loop, then prompt at (as the last prompt) whether to calculate another.

You could, once you get the value, check if the value is 'q'. If it is break, otherwise just continue on.

Thanks for the reply. The program is actually supposed to terminate after the 3rd bmi calculation. What I am not understanding from one of the requirements number 1: You have to use a while loop to allow the user to run up to 3 BMI calculations. If they decide to quit before by entering the letter 'q' for 'quit', they should be allowed to quit the program. In all other cases (i.e. any other input) let them continue with the next BMI calculation. However, after 3 calculations the program should terminate.