h = eval(input(“請輸入你的身高(公尺): “))
while True:
w = eval(input(“請輸入你的體重(公斤),-9999 quit: “))
if w == -9999:
break
bmi = w/(h**2)
#print(bmi)
if 0 < bmi < 18.5:
print(“體重過輕”)
elif 18.5 <= bmi < 24:
print(“正常範圍”)
elif 24 <= bmi < 27:
print(“過重”)
elif 27 <= bmi < 30:
print(“輕度肥胖”)
elif 30 <= bmi < 35:
print(“中度肥胖”)
elif 35 <= bmi:
print(“重度肥胖”)
else:
print(“輸入資料錯誤(BMI<=0)”)
h = eval(input(“請輸入你的身高(公尺),-9999 quit: “))
if h == -9999:
break
改善一點,印出BMI多少:
h = eval(input(“請輸入你的身高(公尺): “))
while True:
w = eval(input(“請輸入你的體重(公斤),-9999 quit: “))
if w == -9999:
break
bmi = w/(h**2)
# print(bmi)
if 0 < bmi < 18.5:
print(“BMI=%.2f,體重過輕” % bmi)
elif 18.5 <= bmi < 24:
print(“BMI=%.2f,正常範圍” % bmi)
elif 24 <= bmi < 27:
print(“BMI=%.2f,過重” % bmi)
elif 27 <= bmi < 30:
print(“BMI=%.2f,輕度肥胖” % bmi)
elif 30 <= bmi < 35:
print(“BMI=%.2f,中度肥胖” % bmi)
elif 35 <= bmi:
print(“BMI=%.2f,重度肥胖” % bmi)
else:
print(“BMI=%.2f,輸入資料錯誤(BMI<=0)” % bmi)
h = eval(input(“請輸入你的身高(公尺),-9999 quit: “))
if h == -9999:
break
近期留言