class Hospital():
"医院类"
def __init__(self,name,addr,type):
self.name = name
self.addr = addr
self.type = type
def accpatient(self):
print("%s开始接受患者"%self.name)
def regpatien(self,price):
# print("治疗费用为%s"%(price))
price = price + 120.50-150
return price
class Patient():
"患者类"
def __init__(self,patientname,age,sex,hospital):
self.patientname = patientname
self.age = age
self.sex =sex
self.hospital = hospital
def tohispital(self):
print("%s去%s检查,检查为:%s"%(self.patientname,self.hospital.name,self.hospital.regpatien(330)))
#实例化医院
hospital = Hospital("无锡市人民医院","江苏省无锡市人民大道","三甲")
#实例化患者
patient1 = Patient("李明",24,"男",hospital)
#调用患者函数方法
patient1.tohispital()
原文地址:http://blog.51cto.com/10836356/2108792