class BMI():
def init(self,height,weight):
self.bmi = weight/height**2
def printBMI(self):
print("Your BMI is {:.2f} ".format(self.bmi))#.2f是保留两位数
class ChinaBMI(BMI): #派生父类
def printBMI(self):
print("Your BMI is {:.2f} ".format(self.bmi)) #.2f是保留两位数
if self.bmi <18.5:
print(“偏瘦,发病危险性低,但其他疾病的危险性增加”)
elif self.bmi <24:
print(“正常,处于平均水平”)
elif self.bmi<27:
print(‘偏胖’)
elif self.bmi<30:
print(‘肥胖’)
elif self.bmi >30:
print(‘重度肥胖’)
h = float(input(‘height:’)) #实列化
w = float(input(‘weight:’))
b=ChinaBMI(h,w)
b.printBMI()