Created
October 22, 2015 17:51
-
-
Save cruor99/23f0e751cb5d308431b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Library(): | |
books = [] | |
def addBooks(self, book): | |
self.books.append(book) | |
def borrowBook(self, bookname): | |
for book in self.books: | |
if book.name == bookname: | |
return self.books.pop() | |
else: | |
return "No such book found" | |
class Book(): | |
bookname = "" | |
@property | |
def name(self): | |
return self.bookname | |
def __init__(self, name): | |
self.bookname = name | |
class Person(): | |
borrowedbooks = [] | |
def borrowbook(self, book): | |
self.borrowedbooks.append(book) | |
@property | |
def showBorrowed(self): | |
return self.borrowedbooks | |
if __name__ == "__main__": | |
person = Person() | |
bok1 = Book("Harry Potter") | |
bok2 = Book("Ringenes Herre") | |
library = Library() | |
library.addBooks(bok1) | |
library.addBooks(bok2) | |
person.borrowbook(library.borrowBook("Harry Potter")) | |
print(person.showBorrowed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment