__init __ () принимает 3 позиционных аргумента, но 4 было дано - PullRequest
0 голосов
/ 14 апреля 2020
class Patient(object):
    '''
    Attributes
    name = Patient name
    age = Patient age
    conditions = Existing patient's conditions
    '''
    status='patient'#-----------class variable-------
    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.'\
              f'Current information: {self.conditions}.')
    def add_info(self,information):
        self.conditions.append(information)    
x=Patient('Yash',21)    
y=Patient('Raj',19)        

class Infant(Patient):

    def __init__(self,name,age):
        self.vaccinations=[]
        super().__init__(self,name,age)

    def add_vac(self,vaccine):
        self.vaccinations.append(vaccine)

    def get_details(self):
        print(f'Patient record: {self.name}, {self.age} years.'\
              f'Patient has had {self.vaccinations} vaccines.'\
              f'Current information: {self.codition}.'\
              f'\n{self.name} IS AN INFACT, HAS HE HAD ALL HIS CHEAKS?')

ash=Infant('Yash',21)

ash.add_vac('MMR')

print(ash.get_details())

1 Ответ

0 голосов
/ 14 апреля 2020

class Patient(object):
    '''
    Attributes
    name = Patient name
    age = Patient age
    conditions = Existing patient's conditions
    '''
    status='patient'#-----------class variable-------
    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.'\
              f'Current information: {self.conditions}.')
    def add_info(self,information):
        self.conditions.append(information)

x=Patient('Yash',21)    
y=Patient('Raj',19)

class Infant(Patient):

    def __init__(self,name,age):
        self.vaccinations=[]
        super().__init__(name,age);

    def add_vac(self,vaccine):
        self.vaccinations.append(vaccine)

    def get_details(self):
        print(f'Patient record: {self.name}, {self.age} years.\
                Patient has had {self.vaccinations} vaccines.\
                Current information: {self.conditions}.\
                {self.name} IS AN INFACT, HAS HE HAD ALL HIS CHEAKS?')

ash=Infant('Yash',21)

ash.add_vac('MMR')

print(ash.get_details())

это только для sh экземпляра ok, x, y - другой экземпляр.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...