Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class client:
- def __init__(self, name, surname):
- self.name = name
- self.surname = surname
- self.borrowedBooks = []
- class library:
- def __init__(self):
- self.__clients = []
- self.__books = []
- def addClient(self, client):
- self.__clients.append(client)
- def printClients(self):
- for client in self.__clients:
- print(client.name + ' ' + client.surname)
- def addBook(self, book):
- self.__books.append(book)
- def printBooks(self):
- for book in self.__books:
- print(book.title + ' ' + str(book.code))
- def lend(self, code, client):
- bookToBorrow = self.findBook(code)
- client.borrowedBooks.append(bookToBorrow)
- def findBook(self, code):
- for book in self.__books:
- if code == book.code:
- return book
- class book:
- def __init__(self, code, title, authors):
- self.authors = authors
- self.code = code
- self.title = title
- class author:
- def __init__(self, name, surname):
- self.name = name
- self.surname = surname
- mainLib = library()
- client1 = client("Jan", "Kowalski")
- mainLib.addClient(client1)
- mainLib.printClients()
- book1 = book(123, 'Robin Hood', 'Sara B.')
- mainLib.addBook(book1)
- mainLib.printBooks()
- mainLib.lend(123,client1)
- print(client1.borrowedBooks[0].title + " is borrowed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement