工程與科技
大學
想半天了
到底錯在哪
終端也可以輸入都沒問題
也有把try except 拿掉還是錯
跪求python大神
Input
Each line contains two numbers, which areheight in centimetersand weight in kilograms.
Output
For each pair of the given height and weight, please print out the results with following rules:
h
If the BMI is less than 18.5 (<= 18.5), please print "underweight".
If the BMI is between 18.5 and 25 (18.5 < BMI <= 25), please print "normal weight".
If the BMI is between 25 and 30(25 < BMI <= 30), please print "overweight".
If the BMI is greater than 30 (> 30), please print "obese".
Sample Input 1
Sample Output 1
160 50
150 60
180 55
normal weight
overweight
underweight
obese
normal weight
163 86
175 57
1
4
Nm in 6 00
7
while True:
try:
height, weight = input("height(cm) and weight(kg):").split()
height = float(height)
weight = float(weight)
bmi = weight/((height/100) **2)
if bmi <= 18.5 :
print("underweight")
elif 18.5 < bmi <= 25 :
print("normal weight")
elif 25 < bmi <= 30 :
print("overweight")
elif 30 < bmi :
print("obese")
except:
exit(wrong)
9
10
11
12
13
14
15
16
17
10
解答
您的問題解決了嗎?
看了這個問題的人
也有瀏覽這些問題喔😉
謝謝你
我後來改成這樣
但跑出來time limited exceed...