Tuesday, 10 September 2013

Python - Input within function

Python - Input within function

Not sure what is wrong with this code, I'm just starting to use Python
2.7, and have run into a problem with this bmi calculator script.
def bmi_calculator():
print "Enter your appelation (Mr., Mrs., Dr., ...): "
appelation = raw_input()
print "Enter your first name: "
fname = raw_input()
print "Enter your last name: "
lname = raw_input()
print "Enter your height in inches: "
height = raw_input()
print "Enter your weight in pounds: "
weight = raw_input()
feet = (height/12)
inches = (height-feet)*12
bmi = ((weight/(height*height))*703)
print "BMI Record for %s %s %s:" % (appelation,fname,lname)
print "Subject is %d feet %d inches tall and weighs %d pounds" %
(feet,inches,weight)
print "Subject's BMI is %d" % (bmi)
Would someone mind telling me what I am doing wrong?



This is the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "a1.py", line 88, in bmi_calculator
feet = (height/12)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

No comments:

Post a Comment