[Tutor] BMI calc
Shall, Sydney
sydney.shall at kcl.ac.uk
Wed Mar 13 15:57:40 CET 2013
On 13/03/2013 12:21, Peter Otten wrote:
> Shall, Sydney wrote:
>
>> I am also a newbie, but I wish to learn, so I offer the following
>> corrections.
>> # Note. I do note know what units you are using.
>> # I would use scientific, metric units. So you need to divide both
>> weight and height by a suitable conversion factors.
>> # Then you will not need the number 703.0, and the units in the second
>> and third lines would be Kg/m. [Kilogram/Metre)
>>
>> def calc_BMI(weight,height):
>> bmi = (weight/(height*height))*703.0
>> print 'Your BMI is : ', BMI 'weight units/height units.' # You need
> to put the correct text here.
>> if bmi <=18.5:
>> print 'underweight'
>> if 18.5 <= bmi <= 24.9:
>> print 'normal weight'
>> if 25.0 <= bmi <= 29.9:
>> print 'overweight'
>> if bmi >= 30:
>> print 'obese'
>> return
> A problem that I have not seen addressed yet:
>
> What will this print for the guy who is 75.0 in high and weighs 200.0 lb?
>
> His bmi is
>
>>>> height = 75.0
>>>> weight = 200.0
>>>> weight/(height*height)*703.0
> 24.995555555555555
>
> That's neither normal nor overweight, according to your categorisation.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Yes, you are right, of course.
Thanks for reminding me that we are dealing with floats.
I should have used approximations, with an (epsilon) error range.
I will remember if future, I hope.
Sydney
--
Professor Sydney Shall,
Department of Haematological Medicine,
King's College London,
Medical School,
123 Coldharbour Lane,
LONDON SE5 9NU,
Tel & Fax: +44 (0)207 848 5902,
E-Mail: sydney.shall,
[correspondents outside the College should add; @kcl.ac.uk]
www.kcl.ac.uk
More information about the Tutor
mailing list