使用Python计算身体质量指数BMI
运行结果如下:
1 ''' 2 3. 利用函数思想,将“身体质量指数BMI”源程序封装成为一个函数并调用。 3 :param height 身高(米) 4 :param weight 体重(公斤) 5 ''' 6 def computeBMI(height, weight): 7 bmi = weight / pow(height, 2) 8 print("BMI的数值为:{:.2f}".format(bmi)) 9 10 if bmi < 18.5: # who国际标准 11 dom = "偏瘦" 12 elif bmi < 25: 13 dom = "正常" 14 elif bmi < 30: 15 dom = "偏胖" 16 else: 17 dom = "肥胖" 18 19 if bmi < 18.5: # dom中国卫生标准 20 who = "偏瘦" 21 elif bmi < 24: 22 who = "正常" 23 elif bmi < 28: 24 who = "偏胖" 25 else: 26 who = "肥胖" 27 28 print("BMI指标为:国际'{0}',国内'{1}'".format(who, dom))
来源:博客园
作者:孤云jh
链接:https://www.cnblogs.com/yijiahao/p/11740478.html