python代码测试健康指数计算器_Python小白一枚,自己写的BMI指数计算器,求教高手一下代码如何重复输入以及如何结束循环?...

展开全部

想让程序循环,在62616964757a686964616fe78988e69d8331333431366335最外层套一个while就可以了,想跳出的时候写break就可以了。

在你的代码中,while不该套在if外面,其次像你这样判断直接用if,就可以了,不需要elseif,直接if效率更高。

想跳出,只要写条件执行break就行,比如下面我的代码中,输入N就结束,输入Y就继续。

while(1):

print('Welcome to use calculator of BMI exponent for human:')

w = float(input('Please enter your weight(kg):'))

h = float(input('Please enter your height(m):'))

BMI = w / (h * h)

if BMI < 18.5: print('you are thin !')

if 18.5 <= BMI <=24.9: print('you are normal !')

if BMI >=25: print('you are little fat !')

if 25.0 < BMI <=29.9: print('you are more little fat !')

if 30.0 <= BMI <= 34.9: print('you are fat !')

if 35.0 <= BMI <=39.9: print('you are serious fat !')

if BMI >=40: print('you are extreme fat !')

print('continue?Y/N')

n=''

while(n!='Y' and n!='N'):

n=input()

if(n=='N'):

break

  • 0
    点赞
  • 0
    收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值