[Tutor] BMI calc

Soliman, Yasmin ysoliman at uncc.edu
Wed Mar 13 04:07:27 CET 2013


I'm using python 2.7, where exactly does the return statment with the (return (weight/(height*height))*703 calculation get posted in the function? 

def calc_BMI(weight,height):
    if bmi <=18.5:
        return 'underweight'
    elif bmi >= 18.5 and bmi <=24.9:
        return 'normal weight'
    elif bmi >=25 and bmi <=29.9:
            return 'overweight'
    elif bmi >=30:
        return 'obese'   

The user will need to input height ex) 5'3 and which will need to be split and stripped in order to convert to inches.
________________________________________
From: Tutor [tutor-bounces+ysoliman=uncc.edu at python.org] on behalf of Mark Lawrence [breamoreboy at yahoo.co.uk]
Sent: Tuesday, March 12, 2013 10:29 PM
To: tutor at python.org
Subject: Re: [Tutor] BMI calc

On 13/03/2013 02:08, Dave Angel wrote:
> On 03/12/2013 09:46 PM, Mark Lawrence wrote:
>> 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.
>>> _
>>>
>>
>> If you're using Python 3 you'll get syntax errors as print is a
>> function, not a statement as in Python 2.  Is this your problem?  If not
>> please cut and paste the exact syntax error for us to see.  Then we'll
>> sort the rest of the problems :)
>>
>
> As Mark implies, tell us exactly what Python version you're using, and
> copy/paste the entire error message, including traceback.
>
> For example, when I run it on 3.3, I have:
>
> davea at think2:~/temppython$ python3.3 soliman.py
>    File "soliman.py", line 6
>      print 'underweight'
>                        ^
> SyntaxError: invalid syntax
>
>
> Also, could you tell us your experience level?  You've defined a
> function, but you haven't called it.  And yet you're apparently trying
> to use the results of calling it.
>
> As for converting height to inches, that depends on what you started
> with.  Since you're using the English version of the formula, you should
> already have inches and pounds before calling that function.
>
> So perhaps in addition to missing the code for inputting the values
> (perhaps the raw_input function), you're also missing the conversion
> from "something" to inches.  How are you getting the raw numbers, and
> what units are they in?
>
> If the raw numbers are in meters and kg, then you'd want to remove the
> multiply by 703.  Or you could convert from meters to inches by
> multiplying by 39.?  (look up the exact number).  And from kg to pounds
> by a similar multiply by something like 2.2
>

Of course if you've got the wrong algorithm you're wasting your time
anyway, see for example
http://www.newscientist.com/article/mg20928030.200-obesity-expert-a-better-fat-measure-than-bmi.html
:)

--
Cheers.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list