Error in Self.vaccination.append(vaccine)
class Patient(object):
''' This is something which I forgot '''
# status = "patient"
def __init__(self, name, age):
self.name = name
self.age = age
self.conditions = []
def get_details(self):
print(f"Patient Record: {self.name} ,{self.age} Years Current Information: {self.conditions}.")
def add_info(self, information):
self.conditions.append(information)
class Infant(Patient):
# vaccination =[] -- Without this throwing error but not in lecture tutorial
def __int__(self, name, age):
self.vaccination = []
super().__init__(name, age)
def add_vac(self, vaccine):
self.vaccination.append(vaccine)
def get_details(self):
print(f"Patient record: {self.name},{self.age} "
f"Patient condition: {self.conditions} "
f"Patient has had {self.vaccination} "
f"\n{self.name} is an infant, has he had all his checks?")
archie = Infant("archie", 4)
archie.add_vac("NMR")
archie.get_details()
Traceback (most recent call last):
File "C:\Users\ASUS\PycharmProjects\Python365\Worksheet1.py", line 301, in <module>
archie.add_vac("NMR")
File "C:\Users\ASUS\PycharmProjects\Python365\Worksheet1.py", line 291, in add_vac
self.vaccination.append(vaccine)
AttributeError: 'Infant' object has no attribute 'vaccination'
Both code and the error attached code seems identical with Gliss notebook but getting an error (solution I knew too i.e declaring Vaccine variable on Class level
but why??)
1 answers ( 0 marked as helpful)
Hey Mayank,
Thank you for reaching out!
Inside the Infant
class, the __init__
function is misspelled as __int__
. That's what causes the trouble.
Kind regards,
365 Hristina