Discuss / Python / 练习

练习

Topic source
w=float(input('w='))
h=float(input('h='))
bmi=w/(h*h)
if bmi<18.5:
print('过轻')
elif 18.5<bmi<25:
print('正常')
elif 25<bmi<28:
print('过重')
elif 28<bmi<32:
 print('肥胖')
else:
 print('严重肥胖')

翡翠two豆

#2 Created at ... [Delete] [Delete and Lock User]

我觉得elif不需要写大于多少,之所以执行本行elif说明上面的不符合上面语句的条件

举个例子:如果输入的体重是76.5625。那你这个程序就报错啦

按你的思路,最好这样写:

if bmi <= 18.5: elif bmi <= 25:    elif bmi <= 32: else:

  • 1

Reply