我使用Python 3.5.1,我需要使用公式703 * weight/height^2來製作一個BMI計算器,輸入我的身高和體重後,我得到「TypeError:不能乘以非序列'str'的類型「如何修復我的代碼以計算Python的身體質量指數?
而且我老實說不知道如何解決它。這是我的代碼。
def calculateBMI():
weight = input("Please enter weight in pounds: ")
height = input("Please enter height in inches: ")
return weight * ((703.0)/(height * height))
bmi = calculateBMI()
print ("""Your BMI is""", str(bmi))
if bmi < 18.5:
print("You are underweight.")
elif bmi > 25:
print("You are overweight.")
else:
print ("You are of optimal weight.")
請問您真正的程序有任何縮進? –
你使用的是Python2還是Python3?Python2具有'raw_input',而Python3則不具備'raw_input'。 –
你運行的是哪個版本的python? raw_input是特定於python2 – snakecharmerb