Re: [Tutor] BMI calc

2013-03-13 Thread Albert-Jan Roskam
>> 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.
> 
> The solution I had in mind is simpler:
> 
> if bmi < 18.5:
>     print "underweight"
> elif bmi < 25:
>     print "normal"
> elif bmi < 30:
>     print "overweight"
> else:
>     print "obese"

How about this approach? the "if" statements are simpler=better, but this is 
fun too!
 
import bisect
 
def getBMI(height, weight, cutoffs=[18, 25, 30],
   categories=('under', 'normal', 'obese', 'morbidly')):
    bmi = weight / float(height ** 2)
return categories[bisect.bisect(cutoffs, bmi)]
 
cutoffs=[18, 25, 30]
categories =('skinny', 'normal', 'teddybear', 'huge teddybear')
print getBMI(1.82, 180, cutoffs, categories)___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-13 Thread Peter Otten
Shall, Sydney wrote:

> 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.995
>>
>> That's neither normal nor overweight, according to your categorisation.

> 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.

The solution I had in mind is simpler:

if bmi < 18.5:
print "underweight"
elif bmi < 25:
print "normal"
elif bmi < 30:
print "overweight"
else:
print "obese"

These give you effectively half-open intervals

18.5 <= bmi < 25 # normal
25 <= bmi < 30 # overweight

but each test relies on the result of the previous ones.

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


Re: [Tutor] BMI calc

2013-03-13 Thread Shall, Sydney

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.995

That's neither normal nor overweight, according to your categorisation.

___
Tutor maillist  -  Tutor@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


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


Re: [Tutor] BMI calc

2013-03-13 Thread Peter Otten
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.995

That's neither normal nor overweight, according to your categorisation.

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


Re: [Tutor] BMI calc

2013-03-13 Thread Altay Aksulu

Assuming the BMI formula is correct, the following is how I would have done it 
in Python 3. You can safely ignore the comments. If you want to run it, copy 
and paste the code into a text editor (you can delete the #comments), save it 
with a .py extension (e.g. bmi.py) and run it from within a terminal screen by 
typing at the shell prompt python3 bmi.py (in Windows command line you may not 
need the 3, I am not sure). If you need further conversions (e.g. converting 
height from ft-in to in or from ft-in to cms and so on) you can add a few more 
lines of code to do that.

def main(): 
 #it is good practice to modularize your program. Hence, this starts with a 
main() function. Defined here and called in the last line. 
w=float(input('Please enter your weight in pounds: '))#You need to 
capture weight and height. input() built-in function is used to get the value 
that will be referenced by the w variable.h=float(input('Please enter your 
height in inches: '))  # Since input() always returns string type, 
float() -another built in function- is used to convert it to a real number.
calc_BMI(w,h) 
#Here you call the BMI calculation function you wrote. Note that you are 
passing w and h values into this function.
def calc_BMI(weight,height):  
#w and h will be assigned to weight and height -in that order- as parameter 
values.bmi=(weight/(height*height))*703.0  
#actual calculation. the result is referenced by the bmi variable.if 
bmi<18.5:
#removed the equal sign here. In your version 18.5 would have fallen into two 
categories.print('underweight')elif bmi>= 18.5 and bmi <=24.9:  
  print('normal weight')elif bmi >=25 and bmi <=29.9:
print('overweight')else:print('obese')
main()
Haven't tried but it should work.
Altay Aksulu.





From: tutor-requ...@python.org
Subject: Tutor Digest, Vol 109, Issue 39
To: tutor@python.org
Date: Wed, 13 Mar 2013 11:44:10 +0100

Send Tutor mailing list submissions to
tutor@python.org
 
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org
 
You can reach the person managing the list at
tutor-ow...@python.org
 
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


--Forwarded Message Attachment--
From: ysoli...@uncc.edu
To: breamore...@yahoo.co.uk; tutor@python.org
Date: Wed, 13 Mar 2013 03:07:27 +
Subject: Re: [Tutor] BMI calc

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@python.org] on behalf of Mark 
Lawrence [breamore...@yahoo.co.uk]
Sent: Tuesday, March 12, 2013 10:29 PM
To: tutor@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 stateme

[Tutor] BMI calc

2013-03-13 Thread Shall, Sydney


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@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.


Yes, as someone pointed out, it would be better if several of the print 
statements were return, as corrected below.

# 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:
return ' You are underweight.'
if  18.5 <= bmi <= 24.9:
return 'Your weight is in the normal range.'
if  25.0 <= bmi <= 29.9:
return 'You are overweight.'
if bmi >= 30:
return 'You are, I regret, obese.'



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

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


Re: [Tutor] BMI calc

2013-03-13 Thread Shall, Sydney

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@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

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


Re: [Tutor] BMI calc

2013-03-13 Thread Alan Gauld

On 13/03/13 03:07, Soliman, Yasmin wrote:

I'm using python 2.7,


Then let us see the syntax errors because otherwise we are guessing.

> where exactly does the return statment ... get posted in the function?

I'm not sure what you mean by 'get posted'
It is activated once the function is called.

ie

def foo(x):
   return 2 + x

does nothing until I call it:

result = foo(5)
print result


def calc_BMI(weight,height):
 if bmi <=18.5:
 return 'underweight'


Since BMI is a value your function is better as it was, just returning 
the value.


The code to convert that BMI value into a weight assessment is better 
done outside, again as you had before. (Or inside another function, 
rateBMI(bmi) maybe)


What was missing was some glue that joins those 2 things together:

read weight and height
call CalcBMI
use result to assess weight.


 elif bmi >= 18.5 and bmi <=24.9:
 return 'normal weight'


BTW in Python you can abbreviate the tests slightly with

elif 18.5 <= bmi <= 24.9:
   print 'normal weight'

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] BMI calc

2013-03-13 Thread Dave Angel

On 03/13/2013 02:17 AM, Jos Kerc wrote:

Hi,


On Wed, Mar 13, 2013 at 4:07 AM, Soliman, Yasmin  wrote:


  

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:



Following return is out of alignment. Should be at the same place in the
line as the oters.



 return 'overweight'


It would certainly look prettier, but it's not a language requirement. 
Only within a single block do the columns have to line up exactly.


> 

--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-12 Thread Jos Kerc
Hi,


On Wed, Mar 13, 2013 at 4:07 AM, Soliman, Yasmin  wrote:

> 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:
>

Following return is out of alignment. Should be at the same place in the
line as the oters.


> 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.
>

Exactly. Do you have a problem with this? If so what?

Dreetz
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-12 Thread Soliman, Yasmin
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@python.org] on behalf of Mark 
Lawrence [breamore...@yahoo.co.uk]
Sent: Tuesday, March 12, 2013 10:29 PM
To: tutor@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@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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-12 Thread Mark Lawrence

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@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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-12 Thread Dave Angel

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@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


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI calc

2013-03-12 Thread Mark Lawrence

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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



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 :)


--
Cheers.

Mark Lawrence

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


[Tutor] BMI calc

2013-03-12 Thread Soliman, Yasmin
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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor