#Python TQC考題406 不定數迴圈-BMI 計算
#第二次做的比較好理解
h=eval(input())
state=””
while h!=-9999:
w=eval(input())
if w == -9999:
break
else:
bmi=w/(h/100)**2
if bmi<18.5:
state=”underweight”
elif 18.5<=bmi<25:
state=”normal”
elif 25.0<=bmi<30:
state=”over weight”
elif 30<=bmi:
state=”fat”
else:
break
print(“BMI:{:.2f}”.format(bmi))
print(“State:”+state)
h=eval(input())
#少這一段,第一次正常,
#之後就能輸入體重,
#身高套用第一次輸入的數值
#轉貼到WP縮排已亂
#做第二次:
print(“請輸入您的身高1st”)
hight=eval(input())
state=””
while hight != -9999:
print(“請輸入你的體重”)
weight = eval(input())
if weight == -9999:break
else:bmi=weight/((hight/100)**2)
#容易忘記身高/100,將cm換算成m
if bmi<18.5:state=”under weight”
elif 18.5<=bmi<25:state=”normal”
elif 25.0<=bmi<30:state=”over weight”
elif 30 <= bmi:state=”fat”
else:break
print(“BMI:{:.2f}”.format(bmi))
print(“State:{:}”.format(state))
print(“請輸入你的身高_迴圈內”)
hight=eval(input())
#第三次做
print(“please input your hight”)
hight = eval(input())
state=””
while hight!=-9999:
print(“please input your weight,-9999 quit”)
weight=eval(input())
if weight==-9999:break
else: bmi=weight/((hight/100)**2)
“””
這一段可將
bmi=weight/((hight/100)**2)
接在weight=eval(input()) 之後
刪掉else
“””
if bmi<18.5:state=”under weight”
elif 18.5<=bmi<25:state=”normal”
elif 25.0<=bmi<30:state=”over weight”
elif 30<=bmi:state=”fat”
print(“BMI: {:.2f}”.format(bmi))
print(“State: {}”.format(state))
print(“please input your hight.-9999 quit”)
hight=eval(input())
“””
while迴圈內要再寫一次
hight=eval(input()) 容易漏
少寫這一段,
hight永遠是迴圈外
第一次輸入的數值
刻意區別迴圈外的hight
往前一行 print(“please input your hight.-9999 quit”)
多寫-9999 quit 提示這時候在迴圈內
“””
#bmi前面沒有非要else
#state起始值其實只要空字串即可