感冒时写代码

博客讲述了感冒时写代码的感受,称比听歌还舒服,调侃自己像传说中的抖M。

感觉比听歌还要舒服=_=b,难道这就是传说中的抖M……

 

以下是一个简单的医院问诊系统的 Python 代码示例: ```python # 医院问诊系统 # 定义患者类 class Patient: def __init__(self, name, age, symptoms): self.name = name self.age = age self.symptoms = symptoms def __str__(self): return f"{self.name}, {self.age} 岁, 症状: {self.symptoms}" # 定义医生类 class Doctor: def __init__(self, name, specialty): self.name = name self.specialty = specialty def diagnose(self, patient): # 根据症状做出诊断 diagnosis = "未知" if "发热" in patient.symptoms: diagnosis = "感冒" elif "头痛" in patient.symptoms: diagnosis = "偏头痛" elif "腹痛" in patient.symptoms: diagnosis = "胃炎" return diagnosis # 定义问诊系统类 class Hospital: def __init__(self): self.patients = [] self.doctors = [] def add_patient(self, patient): self.patients.append(patient) def add_doctor(self, doctor): self.doctors.append(doctor) def diagnose_patient(self, patient_name, doctor_name): # 找到患者和医生 patient = None for p in self.patients: if p.name == patient_name: patient = p break doctor = None for d in self.doctors: if d.name == doctor_name: doctor = d break if not patient or not doctor: print("未找到患者或医生") return # 做出诊断 diagnosis = doctor.diagnose(patient) print(f"{patient.name} 的诊断结果为: {diagnosis}") # 测试代码 if __name__ == "__main__": # 创建医院和医生 hospital = Hospital() doctor1 = Doctor("张医生", "感冒专家") doctor2 = Doctor("李医生", "头痛专家") doctor3 = Doctor("王医生", "胃病专家") hospital.add_doctor(doctor1) hospital.add_doctor(doctor2) hospital.add_doctor(doctor3) # 创建患者并添加到医院 patient1 = Patient("张三", 30, ["发热"]) patient2 = Patient("李四", 25, ["头痛"]) patient3 = Patient("王五", 40, ["腹痛"]) hospital.add_patient(patient1) hospital.add_patient(patient2) hospital.add_patient(patient3) # 进行诊断 hospital.diagnose_patient("张三", "张医生") hospital.diagnose_patient("李四", "李医生") hospital.diagnose_patient("王五", "王医生") ``` 这个例子中,我们定义了三个类:Patient、Doctor 和 Hospital。Patient 类表示患者,Doctor 类表示医生,Hospital 类表示医院。我们在 Hospital 类中定义了一些方法,如添加患者、添加医生和进行诊断等。 在测试代码中,我们创建了一些患者和医生,并将它们添加到医院中。然后,我们调用 diagnose_patient 方法来进行诊断。该方法会找到患者和医生,并调用医生的 diagnose 方法来做出诊断。最后,我们将诊断结果输出到控制台上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值