我需要帮助做我的家庭作业的代码,我有一种感觉,我可能会错过一些东西,您的帮助/反馈将不胜感激!你知道吗
真诚的 梅雷迪斯
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')
您的代码中有几个错误,我已对这些问题进行了注释:
您的代码有多个问题:
将在此处列出:
requestNumber
不是python中的方法。或者导入具有此方法的库。或者使用默认的input
方法。你知道吗weight = requestNumber("Enter weight (kg)")
instead
weight = input("Enter weight (kg)")
例如:
if bmi <= 15:
而且
if bmi=<15
是错误的。应该是if bmi <= 15:
从问题中删除“在此处输入代码”部分。你知道吗
elif bmi >=35 and bmi<=40 enter code here
最后一行代码中的Bug。应该是>;=
elif bmi <=40
print ('Your weight status is Very Severely Obese')
工作代码:
输出:
帮助说明:
试着遵循像pep-8这样的编码约定 [Link]
正确缩进代码。查看如何在“>;=”前后添加空格。这也是pep-89公约的一部分。你知道吗
例如:如果重量大于等于40:
相关问题 更多 >
编程相关推荐