Talk:Python Programming/Source Documentation and Comments

i need help ,please explain this code

import numpy as np class Agent: '''Template for Agent class. Uncallable''' def __init__(self, start_loc, home_loc, start_face): self.bump = False self.dirty = False self.home = False self.loc = start_loc self.home_loc =home_loc self.bearing = self.__bearing__(start_face) self.percept_sequence = [] self.action = 'powerup'

def __bearing__(self, face): Converts an alphanumeric bearing into a coordinate return (np.array([-1,0]) if face=='N'           else np.array([1,0]) if face=='S'            else np.array([0,1]) if face=='E'            else np.array([0,-1]))

def get_percept(self, state): '''       Sets conditions for when each of three onboard detectors should be set to 1 '''       self.bump = False self.dirty = False self.home = False if (min(self.loc + self.bearing) < 0               or min(state.shape - self.loc - self.bearing) == 0                or state[self.loc[0] + self.bearing[0],                            self.loc[1] + self.bearing[1]] == 2): self.bump = True if state[self.loc[0], self.loc[1]] == 1: self.dirty = True # determine if vacuum is in home loc if (self.loc-self.home_loc).sum == 0: self.home = True print (self.bump, self.dirty, self.home) self.percept_sequence.append((self.bump, self.dirty, self.home))