Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- - buggy code - doesn't work properly
- it's an implementation of a list of objects
- problem is retrieving an object out of the list
- since the object is referred as an address in the list
- the test if name not in self.list_Agent is irrelevant because the list isn't indexed by name but by a pointer
- the deleting a object from the list isn't possible either
- only adding object is possible.
- This is how the list_Agent is stored - as object :
- [<__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>]
- """
- class Agent(object):
- def __init__(self, name, level, burnout):
- self.active=True
- self.name=name
- self.level=level
- self.burnout=burnout
- def display(self):
- print "- %s is agent Tier%s with %s level of burnout" % (self.name, self.level, self.burnout)
- def levelup(self):
- self.level+=1
- def fire(self,name):
- self.active=False
- del self # is that even working?
- def hire(self,name):
- self.active=True
- class Center(object):
- """
- Call-Center is a list of Agent
- """
- nb_agent=0
- list_Agent=[]
- def hire(self, name):
- if name not in self.list_Agent:
- self.list_Agent.append(Agent(name,1,0))
- self.nb_agent+=1
- print "** %s has been hired" % name
- else:
- print "Sorry %s already in the list" % name
- def __init__(self, *list_name):
- for name in list_name:
- self.hire(name)
- def display(self):
- print "== list of employee =="
- for i in range(self.nb_agent):
- self.list_Agent[i].display()
- def fire(self,name):
- if name in self.list_Agent:
- id=4
- del self.list_Agent[id]
- self.nb_agent-=1
- print "** %s has been fired" % name
- else:
- print "Sorry %s is not in the list" % name
- my_ccg=Center("Bob Preszkovic", "Jim Bishop", "Barbara O'Reilly", "Peter Munoz")
- my_ccg.display()
- my_ccg.hire("Greg")
- my_ccg.hire("Jim Bishop")
- print "---"
- my_ccg.display()
- my_ccg.fire("Greg")
- print "---"
- print my_ccg.list_Agent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement