Programming in PYTHON Another calculation, and selection) Write a function to ca
ID: 3823420 • Letter: P
Question
Programming in PYTHON
Another calculation, and selection) Write a function to calculate a person's body mass index (BMI), and a function to categorize this index, and add them both to bmi.py. a. bmi(inches, pounds) - returns the index using the formula below. b. category(index) - returns the string category of the index. At left is the formula for calculating BMI, given a person's weight in kilograms and height in meters. Your bmi function starts with the weight in pounds and height in inches, so you must convert to the metric units to calculate BMI. There are 2.20462262 pounds in one kilogram, and there are 39.3700787 inches in a meter. Your category function is passed a bmi value, and it must return one of the strings in this list: 'Underweight', 'Normal', 'Overweight', 'Obese'] in accordance with the following table: Here are some sample results from our solution: -bash-4.2$ python3 bmi.py enter height in inches: 69 enter weight in pounds: 175 BMI is 25.8: Overweight -bash-4.2$ python3 bmi.py enter height in inches: 64.2 enter weight in pounds: 118.5 BMI is 20.2: NormalExplanation / Answer
import sys
height=input("enter height in inches: ")
#Converting height in meters
heightm=height * 0.0254
weight=input("enter weight in pounds: ")
#Converting weight in kilos
weightk=weight/2.20462
#BMI Formula
bmi=weightk/(heightm ** 2.0)
#Rest is Explanatory
if bmi < 18.5:
print "BMI is " +str(bmi)+ " :Underweight"
elif bmi > 18.5 and bmi < 25.0:
print "BMI is " +str(bmi)+ " :Normal"
elif bmi > 25 and bmi < 30.0:
print "BMI is " +str(bmi)+ " :Overweight"
elif bmi > 30.0:
print "BMI is " +str(bmi)+ " :Obese"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.