我在Python 3中计算一个人的BMI,需要检查BMI是否在两个值之间。
这是我的代码:def metricBMI():
text = str('placeholder')
#Get height and weight values
height = float(input('Please enter your height in meters: '))
weight = float(input('Please enter your weight in kilograms: '))
#Square the height value
heightSquared = (height * height)
#Calculate BMI
bmi = weight / heightSquared
#Print BMI value
print ('Your BMI value is ' + str(bmi))
if bmi < 18:
text = 'Underweight'
elif 24 >= bmi and bmi >= 18:
text = 'Ideal'
elif 29 >= bmi and bmi >= 25:
text = 'Overweight'
elif 39 >= bmi and bmi >= 30:
text = 'Obese'
elif bmi > 40:
text = 'Extremely Obese'
print ('This is: ' + text)
这将输出非常好的体重不足,但其他像理想不定义文本。
输出:Calulate BMI, BMR or Harris Benedict Equation (HBE) or exit? bmi
Do you work in metric (M) or imperial (I)m
Please enter your height in meters: 1.8
Please enter your weight in kilograms: 80
Your BMI value is 24.691358024691358
This is: placeholder
我猜我检查变量的方式有问题,但我看不出来。
谢谢
杰克