A program that asks for a few kilograms to reach BMI and standard weight [Python]

In this article A program that asks for a few kilograms from height and weight to BMI and standard weight I will write.

What is BMI / standard weight?

The body mass index (body mass index) is a body mass index that represents the degree of obesity in humans, which is calculated from the relationship between body weight and height. Generally called BMI (Body Mass Index). Body Mass Index-Wikipedia

Normal body weight is the ideal body weight that is statistically certified to be the healthiest human being, with significantly lower mortality and morbidity over a period of time. , Age, height, body fat percentage, etc., all or part of the factors. standard weight-Wikipedia

How to find

BMI ** Standard weight ** Standard weight (kg) = (height (m) x height (m)) x 22

Write the code

** Create a function to calculate BMI and standard weight ** First, pass two arguments to the function. The first is weight The second is height

Since it is only a few kilograms to display the BMI and the appropriate weight, Current weight-standard weight Then find how many kg (difference).

By the way, the unit of height to be acquired this time is "cm", so it is necessary to return it to "m".

`bmi.py`

``````
def getBmi(weight, height):
#Convert height from cm to m
height /= 100

bmi = weight / height ** 2
appropriate = height ** 2 * 22
difference = weight - appropriate
``````

** Find and display body shape from BMI ** What is displayed How many kg is left to BMI / body shape / standard weight is. Body types are classified into three types: lean type (<18.5), standard (18.5 <25), and obese type (> = 25). We will conditionally branch this.

`bmi(2).py`

``````
if bmi < 18.5:
print("BMI: ", '{:.1f}'.format(bmi), "Skinny type up to standard weight", '{:.1f}'.format(difference), "kg increase")
elif bmi < 25:
print("BMI: ", '{:.1f}'.format(bmi), "standard")
elif bmi >= 25:
print("BMI: ", '{:.1f}'.format(bmi), "Obesity up to standard weight", '{:.1f}'.format(difference), "kg weight loss")
``````

The sentence'{: .1f}'.format (bmi) is used to display up to the first decimal place. Also, since it is not necessary to increase or decrease the weight at the time of standard weight, the remaining weight is not displayed.

** Get data and call a function ** Get height and weight in decimal. You can get the decimal number with float (input ()).

`bmi(3).py`

``````

getBmi(w, h)
``````

Overall picture

`bmi(4).py`

``````
def getBmi(weight, height):
height /= 100

bmi = weight / height ** 2
appropriate = height ** 2 * 22
difference = weight - appropriate

if bmi < 18.5:
print("BMI:", '{:.1f}'.format(bmi), "Skinny type up to standard weight", '{:.1f}'.format(difference), "kg increase")
elif bmi < 25:
print("BMI:", '{:.1f}'.format(bmi), "standard")
elif bmi >= 25:
print("BMI:", '{:.1f}'.format(bmi), "Obesity up to standard weight", '{:.1f}'.format(difference), "kg weight loss")

getBmi(w, h)
``````

Execution result

``````Please enter your weight.(kg) → 65
→ BMI: 22.5 standard