[Tutor] BMI calc
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Mar 13 03:29:58 CET 2013
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
More information about the Tutor
mailing list