IBM小练习

'''例一:BMI指数(bmi是计算而来的,但很明显它听起来像是一个属性而非方法,如果我们将其做成一个属性,更便于理解)

成人的BMI数值:
过轻:低于18.5
正常:18.5-23.9
过重:24-27
肥胖:28-32
非常肥胖, 高于32
  体质指数(BMI)=体重(kg)÷身高^2(m)
  EX:70kg÷(1.75×1.75)=22.86
'''


class Conformation:
    def __init__(self,name,sex,hight,weight):
        self.name=name
        self.sex=sex
        self.hight=hight
        self.weight=weight
    @property
    def IBM(self):
        ibm=self.weight/(self.hight**2)
        return ibm
    def healthy_conformation(self):
        a =self.IBM
        if a>18.5 and a<23.9:
            print('健康')
        elif a<18.5:
            print('过轻')
        elif a>28 and a<32:
            print('肥胖')
        elif a>32:
            print('very fat')
        elif a>24 and a<27:
            print('过重')
        else:
            print('亚健康')
dxx= Conformation('dxx','male',1.8,70)
dxx.healthy_conformation()
print(dxx.IBM)
原文地址:https://www.cnblogs.com/accolade/p/10510801.html