在pyschool中回答错误的主题2:问题6

时间:2015-11-24 07:57:09

标签: python

我正在尝试PySchools的练习,我被困在主题:2 Q6。问题如下

  

编写一个函数来计算一个人的BMI。

BMI = weight(kg)  /  ( height(m)*height(m) )  

我试过这段代码

def BMI(weight, height): 
    return "%.1f"%(weight/(height*height))

我得到的结果如下所示

enter image description here

这里有什么问题?

2 个答案:

答案 0 :(得分:3)

操作

weight/(height*height)

返回一个整数(整数)。要使计算成为float,请使用f.ex。

1.0 * weight/(height*height)

答案 1 :(得分:0)

注意:返回1位小数的字符串。

def BMI(weight, height): 
    bmi = float(weight)/(height*height)
    return '%.1f' % bmi