SHOW:
|
|
- or go back to the newest paste.
| 1 | """ | |
| 2 | - | - buggy code - doesn't work properly |
| 2 | + | Newer version - can retrieve element in the list |
| 3 | - | it's an implementation of a list of objects |
| 3 | + | number in the list not changed |
| 4 | no use of pop() | |
| 5 | - | problem is retrieving an object out of the list |
| 5 | + | |
| 6 | - | since the object is referred as an address in the list |
| 6 | + | |
| 7 | - | the test if name not in self.list_Agent is irrelevant because the list isn't indexed by name but by a pointer |
| 7 | + | def hired(self,name): |
| 8 | - | the deleting a object from the list isn't possible either |
| 8 | + | self.active=True |
| 9 | - | only adding object is possible. |
| 9 | + | self.name=name |
| 10 | print "- %s has been hired" % self.name | |
| 11 | - | This is how the list_Agent is stored - as object : |
| 11 | + | |
| 12 | - | [<__main__.Agent object at 0x6fc70>, <__main__.Agent object at 0x6fd10>, <__main__.Agent object at 0x6fe30>, <__main__.Agent object at 0x6fe90>, <__main__.Agent object at 0x6fe50>, <__main__.Agent object at 0x6fe70>] |
| 12 | + | def __init__(self, name, level, burnout): |
| 13 | self.active=True | |
| 14 | self.hired(name) | |
| 15 | - | def __init__(self, name, level, burnout): |
| 15 | + | self.level=level |
| 16 | - | self.active=True |
| 16 | + | self.burnout=burnout |
| 17 | - | self.name=name |
| 17 | + | |
| 18 | - | self.level=level |
| 18 | + | def display(self): |
| 19 | - | self.burnout=burnout |
| 19 | + | print "- %s is agent Tier%s with %s level of stress" % (self.name, self.level, self.burnout) |
| 20 | ||
| 21 | - | def display(self): |
| 21 | + | def levelup(self): |
| 22 | - | print "- %s is agent Tier%s with %s level of burnout" % (self.name, self.level, self.burnout) |
| 22 | + | self.level+=1 |
| 23 | - | |
| 23 | + | |
| 24 | - | def levelup(self): |
| 24 | + | def fired(self,name): |
| 25 | - | self.level+=1 |
| 25 | + | self.active=False |
| 26 | - | |
| 26 | + | print "- %s has been fired" % self.name |
| 27 | - | def fire(self,name): |
| 27 | + | self.name="** fired **" |
| 28 | - | self.active=False |
| 28 | + | |
| 29 | - | del self # is that even working? |
| 29 | + | |
| 30 | - | |
| 30 | + | |
| 31 | - | def hire(self,name): |
| 31 | + | nb_agent=0 |
| 32 | - | self.active=True |
| 32 | + | list_Agent=[] |
| 33 | ||
| 34 | def hire(self, name): | |
| 35 | - | """ |
| 35 | + | not_in=True |
| 36 | - | Call-Center is a list of Agent |
| 36 | + | for n in self.list_Agent: |
| 37 | - | """ |
| 37 | + | if name <> n.name: |
| 38 | - | nb_agent=0 |
| 38 | + | not_in=True |
| 39 | - | list_Agent=[] |
| 39 | + | else: |
| 40 | print "Sorry %s already in the list" % name | |
| 41 | - | def hire(self, name): |
| 41 | + | not_in=False |
| 42 | - | if name not in self.list_Agent: |
| 42 | + | break |
| 43 | - | self.list_Agent.append(Agent(name,1,0)) |
| 43 | + | if not_in==True: |
| 44 | - | self.nb_agent+=1 |
| 44 | + | self.list_Agent.append(Agent(name,1,0)) |
| 45 | - | print "** %s has been hired" % name |
| 45 | + | self.nb_agent+=1 |
| 46 | - | else: |
| 46 | + | |
| 47 | - | print "Sorry %s already in the list" % name |
| 47 | + | def __init__(self, *list_name): |
| 48 | for name in list_name: | |
| 49 | - | def __init__(self, *list_name): |
| 49 | + | self.hire(name) |
| 50 | - | for name in list_name: |
| 50 | + | |
| 51 | - | self.hire(name) |
| 51 | + | def display(self): |
| 52 | - | |
| 52 | + | print "== list of employee ==" |
| 53 | - | def display(self): |
| 53 | + | for n in range(len(self.list_Agent)): |
| 54 | - | print "== list of employee ==" |
| 54 | + | self.list_Agent[n].display() |
| 55 | - | for i in range(self.nb_agent): |
| 55 | + | |
| 56 | - | self.list_Agent[i].display() |
| 56 | + | def fire(self,name): |
| 57 | - | |
| 57 | + | not_in=True |
| 58 | - | def fire(self,name): |
| 58 | + | for n in self.list_Agent: |
| 59 | - | if name in self.list_Agent: |
| 59 | + | if name == n.name: |
| 60 | - | id=4 |
| 60 | + | n.fired(name) |
| 61 | - | del self.list_Agent[id] |
| 61 | + | self.nb_agent-=1 |
| 62 | - | self.nb_agent-=1 |
| 62 | + | not_in=False |
| 63 | - | print "** %s has been fired" % name |
| 63 | + | if not_in==True: |
| 64 | - | else: |
| 64 | + | print "Sorry %s is not in the list" % name |
| 65 | - | print "Sorry %s is not in the list" % name |
| 65 | + | |
| 66 | - | |
| 66 | + | |
| 67 | my_ccg.display() | |
| 68 | print my_ccg.nb_agent | |
| 69 | my_ccg.hire("Greg")
| |
| 70 | my_ccg.hire("Jim Bishop")
| |
| 71 | print "---" | |
| 72 | my_ccg.display() | |
| 73 | my_ccg.fire("Greg")
| |
| 74 | my_ccg.hire("Tom Preston")
| |
| 75 | - | print my_ccg.list_Agent |
| 75 | + | print my_ccg.display() |
| 76 | print my_ccg.nb_agent |