pythoninput算出bmi_python菜鸡——BMI计算

廖雪峰教程的练习:

小明身高1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数:

低于18.5:过轻

18.5-25:正常

25-28:过重

28-32:肥胖

高于32:严重肥胖

用if-elif判断并打印结果。

print('Hi there, plz input your name:')

name = input()

print('hi there, your name is:', name)

print('plz input your height(CM)')

height = input()

print('hi there, your height is:', height)

print('plz input your weight(KG)')

weight = input()

print('hi there, your weight is:', weight)

h = float(height)

w = float(weight)

BMI = w/h/h*10000

if BMI >= 32:

a = '严重肥胖'

elif BMI >=28:

a = '肥胖'

elif BMI >= 25:

a = '过重'

elif BMI >= 18.5:

a = '正常'

else:

a = '太轻'

print('hi %s, here is all your info:' %name)

print('your height and weight is %d cm,'%h)

print('your weight is %d kg' %w)

print('BMI = %.2f, ' %BMI, a)

身高体重本来是int,测试ok,但是体重输了个带小数点的就报错了,就换为float了,取小数点后两位。

其实最后三句,想合在一句写的,但是目前还没法搞定,试了好几种都错了。所以只能分开,或者最后四句写在一起。2020.5.5

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值