#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起始值其實只要空字串即可


![Python socket連線出現[WinError 10049] 內容中所要求的位址不正確 cmd.exe: ipconfig/all ; TCP/IPv4 vs IPv6 Python socket連線出現[WinError 10049] 內容中所要求的位址不正確 cmd.exe: ipconfig/all ; TCP/IPv4 vs IPv6](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/10/20221028151556_42.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python 進階實戰:深入 Word 核心,挖出那一坨 BLOB (含自省 Debug 技巧, BLOB= Binary Large Object) ; part = doc.part.rels[rid].target_part ; return part.blob if “ImagePart” in type(part).__name__ else None Python 進階實戰:深入 Word 核心,挖出那一坨 BLOB (含自省 Debug 技巧, BLOB= Binary Large Object) ; part = doc.part.rels[rid].target_part ; return part.blob if “ImagePart” in type(part).__name__ else None](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2026/01/20260126111046_0_cd8751.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python 如何做excel的樞紐分析? pandas.pivot_table() 或 pandas.DataFrame .groupby() ; 如何指定欄位順序? DataFrame.reindex() ; .sortlevel() ; DataFrame[[col1, col2, col3 ]] ; df.columns.map() ; 如何顯示所有欄? pandas.set_option (“display.max_columns”, None) Python 如何做excel的樞紐分析? pandas.pivot_table() 或 pandas.DataFrame .groupby() ; 如何指定欄位順序? DataFrame.reindex() ; .sortlevel() ; DataFrame[[col1, col2, col3 ]] ; df.columns.map() ; 如何顯示所有欄? pandas.set_option (“display.max_columns”, None)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230323101848_80.png?quality=90&zoom=2&ssl=1&resize=350%2C233)






近期留言