k=0while k==0: H=float(input("身高(m)=")) W=float(input("体重(kg)=")) if H>3 or H<=0 or W<0: print("身高或体重数据异常,请重新输入:") contiune else: BMI=W/(H**2) print("BMI=",BMI) if BMI<15.0: print("Very severely") elif 15<=BMI<=16: print("Severely underweight") elif 16<=BMI<18.5: print("Underweight") elif 18.5<=BMI<25: print("Normal(healthy weight)") elif 25<=BMI<30: print("Overweight") elif 30<=BMI<35: print("Obese ClassI(Mo
derately obese)") elif 35<=BMI<40: print("Obese ClassII(Severely obese)") elif 40<=BMI: print("Obese ClassIII(Very severely obese)") k=float(input("如果你想继续,请输入0,否则将结束。:"))print("程序结束")
k = 0
BMI = 0
while k == 0:
H = float(input("身高(m)="))
W = float(input("体重(kg)="))
if H > 3 or H <= 0 or W < 0:
print("身高或体重数据异常,请重新输入:")
continue
else:
BMI = W / (H ** 2)
print("BMI=", BMI)
if BMI < 15.0:
print("Very severely")
elif 15 <= BMI <= 16:
print("Severely underweight")
elif 16 <= BMI < 18.5:
print("Underweight")
elif 18.5 <= BMI < 25:
print("Normal(healthy weight)")
elif 25 <= BMI < 30:
print("Overweight")
elif 30 <= BMI < 35:
print("Obese ClassI(Moderately obese)")
elif 35 <= BMI < 40:
print("Obese ClassII(Severely obese)")
elif 40 <= BMI:
print("Obese ClassIII(Very severely obese)")
k = float(input("如果你想继续,请输入0,否则将结束。:"))
if k != '0':
print("程序结束")
break
判断最后输入是否为0,如果是则继续,如果不是,则跳出循环,程序退出
代码块格式化一下吧,读起来太困难