SHOW:
|
|
- or go back to the newest paste.
| 1 | class A(): | |
| 2 | def __init__(self, name): | |
| 3 | self.name=name | |
| 4 | def bounce(self): | |
| 5 | - | print "bounced" |
| 5 | + | print "%s bounced" % self.name |
| 6 | self.name="" | |
| 7 | del self | |
| 8 | ||
| 9 | class list_A(): | |
| 10 | list1=[] | |
| 11 | def __init__(self,*name): | |
| 12 | for i in name: | |
| 13 | self.list1.append(A(i)) | |
| 14 | def display(self): | |
| 15 | print "** list of employee:" | |
| 16 | for i in self.list1: | |
| 17 | print "- %s" % i.name | |
| 18 | def hire(self, newname): | |
| 19 | not_in_list=False | |
| 20 | for i in self.list1: | |
| 21 | if newname==i.name: | |
| 22 | print "%s already in Staff" % newname | |
| 23 | not_in_list=False | |
| 24 | return | |
| 25 | else: | |
| 26 | not_in_list=True | |
| 27 | if not_in_list==True: | |
| 28 | self.list1.append(A(newname)) | |
| 29 | print "%s Hired"%newname | |
| 30 | def fire(self,newname): | |
| 31 | not_in_list=True | |
| 32 | idx=0 | |
| 33 | for i in self.list1: | |
| 34 | if newname==i.name: | |
| 35 | - | print "%s found and fired "%newname |
| 35 | + | print "%s found and fired / "%newname, |
| 36 | i.bounce() | |
| 37 | self.list1.pop(idx) | |
| 38 | not_in_list=False | |
| 39 | return | |
| 40 | else: | |
| 41 | - | print "%s not in list" % newname |
| 41 | + | # print "%s not in list" % newname |
| 42 | not_in_list=True | |
| 43 | idx+=1 | |
| 44 | if not_in_list==True: | |
| 45 | print "%s not found"%newname | |
| 46 | my_list=list_A("Tom","Jim","Lisa")
| |
| 47 | my_list.display() | |
| 48 | my_list.hire("Greg")
| |
| 49 | my_list.hire("Jim")
| |
| 50 | my_list.fire("Jim")
| |
| 51 | my_list.fire("John")
| |
| 52 | my_list.hire("Bill")
| |
| 53 | my_list.fire("Tom")
| |
| 54 | my_list.display() | |
| 55 | ||
| 56 | - | # print my_list |
| 56 | + | i=0 |
| 57 | - | # print my_list.list1 |
| 57 | + | for n in my_list.list1: |
| 58 | #print n.name, | |
| 59 | - | for i in my_list.list1: |
| 59 | + | n.bounce() |
| 60 | my_list.list1.pop(i) | |
| 61 | - | #del i |
| 61 | + | i+=1 |
| 62 | - | i.bounce() |
| 62 | + | |
| 63 | - | print "deleted" |
| 63 | + | for n in my_list.list1: |
| 64 | print n.name | |
| 65 | ||
| 66 | print len(my_list.list1) | |
| 67 | ||
| 68 | for i in range(len(my_list.list1)): | |
| 69 | print i | |
| 70 | my_list.list1.pop(i) | |
| 71 | ||
| 72 | print my_list.list1 |