我想爲學校做這個練習,但代碼將無法正常工作,恰恰它不執行if語句後計算BMI。此外,如果輸入不正確,現在檢查除了狀態。請告知代碼中需要更正的內容。謝謝!嘗試,除了和while循環在Python
user_input_1 = input('What is your weight')
user_input_2 = input('What is your height')
b = 'BMI'
b = int(user_input_1)/(float(user_input_2)**2)
while True:
try:
user_input_1 == int and user_input_1 > 0
user_input_2 == float and user_input_2 > 0
print(b)
if b in range(1, 19):
print('You are skinny as a rail')
break
if b in range(19, 26):
print('You are fit as a butcher\'s dog')
break
if b >= 25:
print('You are as plum as a partridge')
break
break
except ZeroDivisionError:
input('Enter your height in meters as a float')
except user_input_1 != int:
input('Please enter your weight in kg')
我們不應該做人民的功課他們,而是隻給指針。 此外,在這種情況下循環可能比遞歸更好。 – SpoonMeiser