height = float(input('height: '))
weight = float(input('weight: '))
BMI = weight/(height**2)
if BMI <18.5:
print('过轻')
elif 18.5 <= BMI <=25:
print('正常')
elif 25 <= BMI <= 28:
print('过重')
elif 28 <= BMI <= 32:
print('肥胖')
else:
print('严重肥胖')
bmi = 25和28的时候你觉得输出的结果是啥?
C:\work>python age.py
height: 1
weight: 25
正常
weight: 28
过重
代码不够严谨,不过输出结果是由上往下的,上面条件符合就直接输出了
Sign in to make a reply
留君于心
height = float(input('height: '))
weight = float(input('weight: '))
BMI = weight/(height**2)
if BMI <18.5:
print('过轻')
elif 18.5 <= BMI <=25:
print('正常')
elif 25 <= BMI <= 28:
print('过重')
elif 28 <= BMI <= 32:
print('肥胖')
else:
print('严重肥胖')