体质指数

Python计算身体质量指数BMI

匿名 (未验证) 提交于 2019-12-02 22:51:30
使用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

身体质量指数BMI

浪尽此生 提交于 2019-11-27 02:57:43
思路方法:难点在于同时输出国内和国际回应的的分类 #CalBMI.py; height,weight = eval(input("请输入身高(米)和体重(公斤)【逗号隔开】:")) bmi = weight / pow(height,2) print("BMI的值为:{:.2f}".format(bmi)) who,nat = "","" if bmi<18.5: who,nat = "偏瘦","偏瘦" elif 18.5<=bmi<24: who,nat = "正常","正常" elif 24<=bmi<25: who,nat = "正常","偏胖" elif 25<=bmi<28: who,nat = "偏胖","偏胖" elif 28<=bmi<30: who,nat = "偏胖","肥胖" else: who,nat = "肥胖","肥胖" print("BMI指标为:国际'{0}',国内'{1}'".format(who,nat)) 来源: https://blog.csdn.net/zykcxk666/article/details/99300380

身体质量指数BMI

孤人 提交于 2019-11-26 14:13:56
Solution: 方法一:"Python语言程序设计"(中国大学MOOC平台)的答案 分析:对比两种指标,将共性(相同的区间)和异性(不同的区间)细分。这样两种指标的判断条件(不等式)会一致,从而所分的每个区间都只用一条判断语句即可处理,同时将处理的结果一次性赋值给两个变量 方法二:本人的答案 1 def gj(bmi): 2 if bmi<18.5: 3 a = "偏瘦" 4 elif 18.5<=bmi<25: 5 a = "正常" 6 elif 25<=bmi<30: 7 a = "偏胖" 8 else: 9 a = "肥胖" 10 return a 11 def gn(bmi): 12 if bmi<18.5: 13 b = "偏瘦" 14 elif 18.5<=bmi<24: 15 b = "正常" 16 elif 24<=bmi<28: 17 b = "偏胖" 18 else: 19 b = "肥胖" 20 return b 21 def main(): 22 height, weight = eval(input()) 23 bmi= round(weight/(height**2),2) 24 c = gj(bmi) 25 d = gn(bmi) 26 print("BMI数值为:{}".format(bmi)) 27 print("BMI指标为:国际'{}'