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
總結
以上是生活随笔為你收集整理的python代码测试健康指数计算器_Python小白一枚,自己写的BMI指数计算器,求教高手一下代码如何重复输入以及如何结束循环?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS2017 打包 从与我的应用程序相
- 下一篇: python logistic步骤_Py