In: Computer Science
Using Python,
Write an app for patients such as patients requiring surgery and patients who are pregnant and relevant functionalities.
Note : It's not a complex app. It is for my fundamental 2 class to understand the inheritance concept. Simpler the better.
Thanks for posting the question, here is a simple python code that demonstrates inheritance using the given example in the question. Please refer the screenshot for the code indentation and output
Incase you have any questions, do post it, and i'll be happy to assist you right away !
_____________________________________________________________________________________________
class Patient(): def __init__(self, name,admission_date,doctor_name): self.name=name self.admission_date=admission_date self.dr_name=doctor_name def get_patient_name(self): return self.name def get_admission_date(self): return self.admission_date def get_doctor_name(self): return self.dr_name def __str__(self): return self.name+' was admitted on '+self.admission_date+' and is under Dr. '+self.dr_name class Surgery(Patient): def __init__(self,name, dt,doctor_name,surgery_type,surgery_date): super().__init__(name, dt, doctor_name) self.surgery_type=surgery_type self.surgery_date=surgery_date def get_surgery_type(self): return self.surgery_type def set_surgery_type(self,type): self.surgery_type=type def get_surgery_date(self): return self.surgery_date def set_surgery_date(self,date): self.surgery_date=date def __str__(self): return Patient.__str__(self)+' and will undergo '+self.surgery_type+' surgery on '+self.surgery_date class Pregnant(Patient): def __init__(self,name, dt,doctor_name,pregnancy_weeks): super().__init__(name, dt, doctor_name) self.weeks=pregnancy_weeks def get_pregnancy_weeks(self): return self.weeks def get_weeks_left(self): return 9*4-self.weeks def __str__(self): return Patient.__str__(self)+ ' is '+str(self.weeks)+' weeks pregnant and expecting after '+str(self.get_weeks_left())+' weeks.' peter=Surgery('Peter','02/06/2019','William Cambell','Appendectomy','02/10/2019') print(peter) peter.set_surgery_date('03/01/2019') peter.set_surgery_type('Cholecystectomy') print(peter) alice=Pregnant('Alice','02/06/2019','Sarah Williams',30) print(alice) _____________________________________________________________________________________
image screenshot
thank you !
: )