[Tutor] BMI calc

Shall, Sydney sydney.shall at kcl.ac.uk
Wed Mar 13 11:44:02 CET 2013


On 13/03/2013 00:05, Soliman, Yasmin wrote:
> Hello all,
>
> I'm new to python and its been a stuggle so far. I'm attempting to create a BMI calculator in Wing 101 4.1. I keep getting syntax errors:
>
> def calc_BMI(weight,height):
>      return (weight/(height*height))*703.0
> if bmi <=18.5:
>      print 'underweight'
> elif bmi >= 18.5 and bmi <=24.9:
>          print 'normal weight'
> elif bmi >=25 and bmi <=29.9:
>              print 'overweight'
> elif bmi >=30:
>                  print 'obese'
>
> Also, height should be converted to inches and I have not the slightest clue how to so. Any help would be much appreciated.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Hi,
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

I hope that I am halfway correct.
With best wishes,
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130313/5540d633/attachment-0001.html>


More information about the Tutor mailing list