conversion_factor = 703 healthy_bmi = 24.9 print "Your height in inches" height = float(raw_input("> ")) #height = 66.0 print "Your weight in pounds" weight = float(raw_input("> ")) #weight = 165.0 #print height #print weight def get_bmi(weight, height): height_squared = pow(height,2) # print "height squared: ", height_squared weight_by_height_squared = weight / height_squared # print "weight_by_height_squared:", weight_by_height_squared bmi = round(weight_by_height_squared * conversion_factor, 1) return bmi def my_bmi(current_weight, height): current_bmi = get_bmi(current_weight, height) # print "current_bmi: ", current_bmi bmi_diff = abs(round(healthy_bmi - current_bmi,2)) healthy_weight = round((healthy_bmi / 703) * pow(height, 2), 2) weight_diff = round(abs(current_weight - healthy_weight), 2) percent_diff = round((weight_diff / current_weight) * 100, 2) # print weight_diff if current_bmi <= 18: print "You're underweight. Go see a doctor!!!!" elif current_bmi <=18.5: print "You're thin for your height. Time to chub it up!" elif current_bmi <= healthy_bmi: print "Relax you're healthy for your height. Your BMI is %r" % current_bmi elif current_bmi <= 29.9: print "Your BMI is %r.\nYou need to lose %r on your BMI to get to 24.9.\nThat means losing %r pounds (%r%%) to get to your max healthy weight of %r." % (current_bmi, bmi_diff, weight_diff, percent_diff, healthy_weight) else: print "Your BMI is %r. You're obese. You're over your healthy BMI of 24.9 by %r. That means losing %r pounds. See the doctor!!!!" % (current_bmi, bmi_diff, weight_diff) my_bmi(weight, height)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question