SHOW:
|
|
- or go back to the newest paste.
| 1 | """ | |
| 2 | - | Newer version - can retrieve element in the list |
| 2 | + | list is now updated |
| 3 | - | number in the list not changed |
| 3 | + | |
| 4 | - | no use of pop() |
| 4 | + | |
| 5 | def hired(self,name): | |
| 6 | self.active=True | |
| 7 | self.name=name | |
| 8 | print "- %s has been hired" % self.name | |
| 9 | ||
| 10 | def __init__(self, name, level, burnout): | |
| 11 | self.active=True | |
| 12 | self.hired(name) | |
| 13 | self.level=level | |
| 14 | self.burnout=burnout | |
| 15 | ||
| 16 | def display(self): | |
| 17 | print "- %s is agent Tier%s with %s level of stress" % (self.name, self.level, self.burnout) | |
| 18 | ||
| 19 | def levelup(self): | |
| 20 | self.level+=1 | |
| 21 | ||
| 22 | def fired(self,name): | |
| 23 | self.active=False | |
| 24 | print "- %s has been fired" % self.name | |
| 25 | self.name="** fired **" | |
| 26 | ||
| 27 | ||
| 28 | class Center(object): | |
| 29 | nb_agent=0 | |
| 30 | list_Agent=[] | |
| 31 | ||
| 32 | def hire(self, name): | |
| 33 | not_in=True | |
| 34 | for n in self.list_Agent: | |
| 35 | if name <> n.name: | |
| 36 | not_in=True | |
| 37 | else: | |
| 38 | print "Sorry %s already in the list" % name | |
| 39 | not_in=False | |
| 40 | break | |
| 41 | if not_in==True: | |
| 42 | self.list_Agent.append(Agent(name,1,0)) | |
| 43 | self.nb_agent+=1 | |
| 44 | ||
| 45 | def __init__(self, *list_name): | |
| 46 | for name in list_name: | |
| 47 | self.hire(name) | |
| 48 | ||
| 49 | def display(self): | |
| 50 | print "== list of employee ==" | |
| 51 | for n in range(len(self.list_Agent)): | |
| 52 | self.list_Agent[n].display() | |
| 53 | ||
| 54 | def fire(self,name): | |
| 55 | not_in=True | |
| 56 | idx=0 | |
| 57 | for n in self.list_Agent: | |
| 58 | if name == n.name: | |
| 59 | n.fired(name) | |
| 60 | self.nb_agent-=1 | |
| 61 | self.list_Agent.pop(idx) | |
| 62 | not_in=False | |
| 63 | idx+=1 | |
| 64 | if not_in==True: | |
| 65 | print "Sorry %s is not in the list" % name | |
| 66 | ||
| 67 | my_ccg=Center("Bob Preszkovic", "Jim Bishop", "Barbara O'Reilly", "Peter Munoz")
| |
| 68 | my_ccg.display() | |
| 69 | print my_ccg.nb_agent | |
| 70 | my_ccg.hire("Greg")
| |
| 71 | my_ccg.hire("Jim Bishop")
| |
| 72 | print "---" | |
| 73 | my_ccg.display() | |
| 74 | - | my_ccg.hire("Tom Preston")
|
| 74 | + | |
| 75 | my_ccg.hire("Reggy")
| |
| 76 | my_ccg.fire("Jim Bishop")
| |
| 77 | my_ccg.hire("Ronald")
| |
| 78 | print my_ccg.display() | |
| 79 | print my_ccg.nb_agent |