首页 > 编程知识 正文

python分片赋值怎么解决,python中变量类型判断方法

时间:2023-05-05 20:33:01 阅读:254135 作者:3711

我在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

我猜我检查变量的方式有问题,但我看不出来。

谢谢

杰克

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。