#子类调用父类
class Calc:
def __init__(self):
self.data = []
def append2(self, x):
self.data.append(x)
print(self.data)
class Calc_child(Calc):
def add(self, a, b):
return a/b**2
c_child = Calc_child()
c_child.append2(4)
print(c_child.data)
print(c_child.add(4, 4))
'''
[4]
[4]
0.25
'''
#重新定义主类的方法 printBMI(self)
class BMI:
def __init__(self,height,weight):
self.bmi = weight/height**2
def printBMI(self):
print("Your BMI is {:.1f}".format(self.bmi))
class ChinaBMI(BMI):
def printBMI(self):
print("你的BMl是{:.1f}".format(self.bmi))
if self.bmi < 18.5:
print("偏瘦!")
elif self.bmi < 24:
print("稍瘦")
elif self.bmi< 26:
print("正常")
elif self.bmi < 28:
print("偏胖")
else:
print("肥胖")
h = float(input("height="))
w = float(input("wight="))
x = ChinaBMI(h,w)
x.printBMI()