Python中的BMI索引
我需要帮助为我的家庭作业编写代码,我感觉我可能遗漏了一些东西,非常感谢您的帮助/反馈 诚恳 梅雷迪斯Python中的BMI索引,python,Python,我需要帮助为我的家庭作业编写代码,我感觉我可能遗漏了一些东西,非常感谢您的帮助/反馈 诚恳 梅雷迪斯 def calc_BMI(): weight=requestNumber("Enter weight (kg)") height=requestNumber("Enter Height (meters)") bmi=(weight/(height*height)) print 'Your BMI in %2f' % bmi if bmi=<15 p
def calc_BMI():
weight=requestNumber("Enter weight (kg)")
height=requestNumber("Enter Height (meters)")
bmi=(weight/(height*height))
print 'Your BMI in %2f' % bmi
if bmi=<15
print('Your weight status is Very Severely Underweight')
elif bmi>=15.0 and bmi<=16.0
print ('Your weight status is Severely Underweight')
elif bmi>=16.0 and bmi<=18.5
print ('Your weight status is Underweight')
elif bmi>= 18.5 and bmi <=25
print('Your weight staus is Normal')
elif bmi >=25 and bmi <=30
print ('Your weight status is Overweight')
elif bmi>=30 and bmi <=35
print ('Your weight status is Moderately Obese')
elif bmi >=35 and bmi<=40
print ('Your weight status is Severely Obese')
elif bmi <=40
print ('Your weight status is Very Severely Obese')
def calc_BMI():
重量=请求数量(“输入重量(kg)”)
高度=请求编号(“输入高度(米)”)
体重指数=(体重/(身高*身高))
在%2f“%BMI”中打印“您的体重指数”
如果bmi=15.0,bmi=16.0,bmi=18.5,bmi=25,bmi=30,bmi=35,bmi您的代码存在多个问题:
将在此处列出它们:
requestNumber
不是python中的方法。导入具有此方法的库。或者使用默认的input
方法
weight=requestNumber(“输入重量(kg)”)
取而代之
weight=输入(“输入重量(kg)”)
在if条件结束时,您应该有一个“:”
例如:如果bmi您的代码中有几个错误,我已经对这些问题进行了评论:
def calc_BMI():
weight=int(input("Enter weight (kg)"))#make sure value taken is int
height=float(input("Enter Height (meters)"))#make sure value taken is float
bmi=(weight/(height**2))#use the power operator for squaring instead
print ('Your BMI in %2f' % bmi)
if bmi <= 15 :#colon eexpected
print('Your weight status is Very Severely Underweight')
elif bmi>=15.0 and bmi<=16.0:#colon eexpected
print ('Your weight status is Severely Underweight')
elif bmi>=16.0 and bmi<=18.5:#colon eexpected
print ('Your weight status is Underweight')
elif bmi>= 18.5 and bmi <=25 :#colon eexpected
print('Your weight staus is Normal')
elif bmi >=25 and bmi <=30:#colon eexpected
print ('Your weight status is Overweight')
elif bmi>=30 and bmi <=35:#colon eexpected
print ('Your weight status is Moderately Obese')
elif bmi >=35 and bmi<=40:#colon eexpected
print ('Your weight status is Severely Obese')
else:#no need for a elif,rather use else for the rest
print('Your weight status is Very Severely Obese')
calc_BMI()# call the function to run
def calc_BMI():
重量=整数(输入(“输入重量(kg)”)#确保取的值为整数
高度=浮动(输入(“输入高度(米)”)#确保取的值为浮动
bmi=(体重/(身高**2))#使用幂运算符进行平方运算
打印(“%2f”%BMI)中的您的体重指数
如果bmi=15.0,bmi=16.0,bmi=18.5,bmi=25,bmi=30,bmi=35,bmi=35,则最后的elif
应具有bmi>=40
。但是,你到底要问什么?在你的<代码>之后,你需要添加冒号(:):如果 S和<代码> ELIF S,即:“BME,你也可能想考虑简化<代码> BMI>=16,BMI=BMI。你忘了问一个问题。我建议用<代码>浮动(高度)替换<代码>浮动(高度)*浮动(高度)< /代码>。**2
。谢谢!我能看到并理解所做的改变。
calc_BMI()
Enter weight (kg)78
Enter Height (meters)1.8
Your BMI in 24.074074
Your weight staus is Normal
def calc_BMI():
weight=int(input("Enter weight (kg)"))#make sure value taken is int
height=float(input("Enter Height (meters)"))#make sure value taken is float
bmi=(weight/(height**2))#use the power operator for squaring instead
print ('Your BMI in %2f' % bmi)
if bmi <= 15 :#colon eexpected
print('Your weight status is Very Severely Underweight')
elif bmi>=15.0 and bmi<=16.0:#colon eexpected
print ('Your weight status is Severely Underweight')
elif bmi>=16.0 and bmi<=18.5:#colon eexpected
print ('Your weight status is Underweight')
elif bmi>= 18.5 and bmi <=25 :#colon eexpected
print('Your weight staus is Normal')
elif bmi >=25 and bmi <=30:#colon eexpected
print ('Your weight status is Overweight')
elif bmi>=30 and bmi <=35:#colon eexpected
print ('Your weight status is Moderately Obese')
elif bmi >=35 and bmi<=40:#colon eexpected
print ('Your weight status is Severely Obese')
else:#no need for a elif,rather use else for the rest
print('Your weight status is Very Severely Obese')
calc_BMI()# call the function to run