# L-24 MCS 260 Mon 24 Oct 2007 : class People class People: """ The class People collects information of all librarians and patrons of the library. """ whoswho = [] current = '' def __init__(self): "Creates a root user." import classperson root = classperson.Person() root.create(name='root',PIN=0,status=True) self.whoswho = [root] def search(self,name): """ Returns -1 if name not in self.whoswho, else the person object is returned. """ for p in self.whoswho: if p.name == name: return p else: return -1 def logon(self): """ Prompts for name and PIN, and returns -1 if access is not granted; 0 if the user is a patron; +1 if the user is a librarian. """ name = raw_input('Give your name : ') member = self.search(name) if member.PIN < 0: print 'you are not a member' return -1 else: PIN = input('Give your PIN : ') if PIN == member.PIN: print 'welcome ' + member.name self.current = member if member.librarian: return +1 else: return 0 else: print 'wrong PIN' return -1 def who(self): "Shows who is currently logged in." if self.current == '': print 'nobody is logged in' else: print self.current.name + ' is logged in' def logoff(self): "The current user is logged off." if self.current != '': print 'bye bye, ' + self.current.name self.current = '' def add(self): "Adds a new person to the collection." import classperson p = classperson.Person() p.create() self.whoswho.append(p) def delete(self): "Prompts for a name and then deletes." name = raw_input('Give name : ') for k in range(0,len(self.whoswho)): p = self.whoswho[k] if p.name == name: d = self.whoswho.pop(k) d.show() print 'has been deleted' break