下面我提到了我的数据,我正在尝试使用范围类(19-25)进行输出,但不知怎的,我不理解它。 - 项目清单 如果输出小于19,我想得到这样的结果 如果输出在19-25之间,那么说“你很瘦如铁” 如果输出超过,那么说“你适合作为屠夫的狗” 25然后说“你像鹧pl一样梅花”
这是我的输出数据
a=float(input('what is your weight(kg)'))
b=float(input('what is your height(cm)'))
operations=[(a)/(b*b/100)*100]
output=operations
print("Your BMI is", output, "you are skinny as a rail.")
答案 0 :(得分:0)
我不完全了解您的BMI公式,但Metric中的正确公式是
BMI = Weight / (Height)^2
我在我的例子中使用它,但您可以根据自己的喜好自由更改它。也没有必要将操作转换为列表。如果某人决定输入字母而不是数字,那么您的代码将无法运行,因此最好对其进行验证。
>>> def bmi ():
... try:
... weight = float (input ('Weight in Kgs: '))
... height = float (input ('Height in Meters: '))
... bmi = weight / (height * height)
... if bmi < 19:
... print ('Your BMI: %.2f. You\'re skinny.' % bmi)
... elif 19 <= bmi <= 25:
... print ('Your BMI: %.2f. You\'re fit.' % bmi)
... else:
... print ('Your BMI: %.2f. You\'re plum.' % bmi)
... except ValueError:
... print ('Only numbers are accepted!')
...
>>>
<强>输出强>
>>> bmi ()
Weight in Kgs: 80
Height in Meters: 1.7
Your BMI: 27.68. You're plum.
>>> bmi ()
Weight in Kgs: 60
Height in Meters: 1.7
Your BMI: 20.76. You're fit.
>>> bmi ()
Weight in Kgs: 50
Height in Meters: 1.8
Your BMI: 15.43. You're skinny.
>>> bmi ()
Weight in Kgs: 65
Height in Meters: a
Only numbers are accepted!