Discuss / Python / 结合前几节的内容拼凑出来的扩展,总觉得应该有更简单的方式达到目的=_=

结合前几节的内容拼凑出来的扩展,总觉得应该有更简单的方式达到目的=_=

Topic source

MyView_MyLife

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

-- coding: utf-8 --

h=input('请输入身高:') h=float(h)

#判断一下输入的是以米位单位还是以厘米为单位

if h>0 and h<3: #默认人类身高不超过三米吧... h=h elif h>0and h<300: h=h/100 else: print('ERROR!')

#请问怎么返回到之前的步骤重新开始输入身高?

w=input('请输入体重:')

#主要是不知道以什么标准来判断输入的是市还是公斤因此没判断,请各位指教?

w=float(w) bmi=w/(h*h) b='%.1f' % bmi if bmi>32: print('BMI值:',b,',''严重肥胖') elif bmi>=28: print('BMI值:',b,',''肥胖') elif bmi>=25: print('BMI值:',b,',''过重') elif bmi>=18.5: print('BMI值:',b,',''正常') else : print('BMI值:',b,',''过轻')

lsl787878

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

我学习了下您的代码,看过循环后做的修改。 望指教 else: while h>=300: print('error') h=input('重新输入:') h=float(h) print(h)

不过不可以再修改数字的单位了比如再输入220cm,则需要另作判断。


  • 1

Reply