It's more recent, but I wanted to do BMI calculation with python. As a personal hobby. It's just a personal note.
With two python files
health_check.py
# coding: UTF-8
#Since the environment is Mac OS, UTF for Japanese support-8
#BMI code
#The name is health_check.py
def bmi(weight, height):
bmi_data = []
w = weight
h = height
bmi = w/(h*h)
bmi = round(bmi, 1)
bmi_data.append(bmi)
if bmi<18.5:
ans = "It is a thin type"
elif bmi>=18.5 and bmi<25:
ans = "Standard"
else:
ans = "I'm obese"
bmi_data.append(ans)
return bmi_data
The second is health_check_main.py.
health_check_main.py
# coding: UTF-8
# BMI health_check main
# health_check_main.py
import health_check
weight = float(input('Please enter your weight(kg): '))
height0 = float(input('Please enter your height(cm): '))
height = height0/100
bj = health_check.bmi(weight, height)
print("----" * 10)
print("Your BMI: " + str(bj[0]) + '\n your body shape: ' + bj[1])
Execution is as follows with the bash command of the Mac OS terminal.
health_check_main.sh
$ python health_check_main.py
Please enter your weight(kg): 55
Please enter your height(cm): 160
----------------------------------------
Your BMI: 21.5
Your body shape:Standard
that's all.
Recommended Posts