health-data-science-OR / coding-for-ml

Learning materials for Coding for Machine Learning and Data Science
https://www.pythonhealthdatascience.com
MIT License
15 stars 4 forks source link

Issue on page /content/01_algorithms/06_solutions/02_basic_oop.html #21

Closed TomMonks closed 2 years ago

TomMonks commented 2 years ago

Exercise 4:

init method breaks PEP8 for line length.

suggested fix:

class Hospital:
    '''
    Encapsulates a hosptial made up of wards...
    '''
    def __init__(self, n_patients, age_ranges):
        self.wards = [new_ward(i, n_patients[i], age_ranges[i]) 
                               for i in range(len(n_patients))]

    def add_patient(self, ward_id, patient):
        self.wards[ward_id].add_patient(patient)

    def add_ward(self, n_patients=0, age_range=(60, 95)):
        to_add = new_ward(len(self.wards), n_patients, age_range)
        self.wards.append(to_add)

    @property
    def n_patients(self):
        return sum([ward.n_patients for ward in self.wards])

    @property
    def n_wards(self):
        return len(self.wards)
TomMonks commented 2 years ago

fixed in Dev

TomMonks commented 2 years ago

Now live at pythonhealthdatascience.com