Discuss / Python / BMI的输出结果如何保留小数点后两位

BMI的输出结果如何保留小数点后两位

Topic source

叕樢

#1 Created at ... [Delete] [Delete and Lock User]
h=float(input('enter your height(M)'))
w=float(input('enter your weight(KG)'))
b=w/(h*h)
if b<18.5:
    print('过轻')
elif 18.5>b<25:
    print('正常')
elif 25>b<28:
    print('过重')
elif 28>b<32:
    print('肥胖')
else:
    print('严重肥胖')
print('BMI:'b)

叕樢

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

判断好写反了。。。。不要在意细节

叕樢

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

改一下

h=float(input('enter your height(M)'))
w=float(input('enter your weight(KG)'))
b=w/(h*h)
if b<18.5:
    print('过轻')
elif 18.5<b<25:
    print('正常')
elif 25<b<28:
    print('过重')
elif 28<b<32:
    print('肥胖')
else:
    print('严重肥胖')
print('BMI'b)

  • 1

Reply