visitor pattern this is lot cleaner than the types of output you will encounter in the real worldbut this is good representation of the messy nature of real-world devices we now have simulation of network of devices we can move on to the parts we are really interested innamely doing something with these devices the first thing we are interested in is checking the status of the device attached to the object to determine if the device is online or not let' create flat collection containing the nodes in the network and then implement an is_online method to tell us if the device is online or not thenwe can look at each device in turn and ask if it is online or not we also added name parameter to each constructor so we can easily see what device we are currently dealing with import random class light(object)def __init__(selfname)self name name def get_status(self)return random choice(range(- , )def is_online(self)return self get_status(!- class thermostat(object)def __init__(selfname)self name name def get_status(self)temp_range [ for in range(- )temp_range append(nonereturn random choice(temp_rangedef is_online(self)return self get_status(is not none class temperatureregulator(object)def __init__(selfname)self name name