class BMI:
def __init__(self,name,age,weight,high):
self.name = name
self.age = age
self.weight = weight
self.high = high
def say_hello(self):
self.jieguo=self.weight/self.high/self.high
print("{n}的BMI值为{m}".format(n=self.name,m=self.jieguo))
m = self.jieguo
if m < 18.5 :
print ("偏瘦")
elif m < 24 :
print ("正常")
elif m < 30 :
print ("偏胖")
elif m > 30:
print ("肥胖")
#实例化
zhangsan = BMI("zhangsan","18",70,1.75)
# 调用方法
zhangsan.say_hello()
zhangsan的BMI值为22.857142857142858
正常