Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(object):
- def __init__(self, name, email):
- self.name = name
- self.email = email
- self.books = {}
- def get_email(self):
- return self.email
- def change_email(self, address):
- self.email = address
- print("Your email has been updated to " + address)
- def __repr__(self):
- return "User: {}, email: {}, books read: {}".format(self.name, self.email, self.books)
- def __eq__(self, other_user):
- return self.name == other_user.name and self.email == other_user.email
- def read_book(self, book, rating = None):
- #self.books = {}
- self.books.update({book : rating})
- return self.books
- def get_average_rating(self):
- for value in self.books:
- average = sum(self.books)/len(self.books)
- return average
- class Book(object):
- def __init__(self, title, isbn):
- self.title = title
- self.isbn = isbn
- self.ratings = []
- def get_title(self):
- return self.title
- def get_isbn(self):
- return self.isbn
- def set_isbn(self, new_isbn):
- self.isbn = new_isbn
- print("This book's ISBN has been updated to " + str(new_isbn))
- def add_rating(self, rating):
- if rating > 0 < 4:
- self.ratings.append(rating)
- else:
- print("Invalid Rating")
- def __eq__(self, other_book):
- return self.title == other_book.title and self.isbn == other_book.isbn
- def get_average_rating(self):
- for value in self.ratings:
- average = sum(self.ratings)/len(self.ratings)
- def __hash__(self):
- return hash((self.title, self.isbn))
- class Fiction(Book):
- def __init__(self, title, author, isbn):
- super().__init__(title, isbn)
- self.author = author
- def get_author(self):
- return self.author
- def __repr__(self):
- return "{} by {}".format(self.title, self.author)
- class Non_Fiction(Book):
- def __init__(self, title, subject, level, isbn):
- super().__init__(title, isbn)
- self.subject = subject
- self.level = level
- def get_subject(self):
- return self.subject
- def get_level(self):
- return self.level
- def __repr__(self):
- return "{}, a {} manual on {}".format(self.title, self.level, self.subject)
- user1 = User("Sarah Lane", "sarahlane@gmail.com")
- user2 = User("Sarah Lane", "saralane@gmail.com")
- print(user1)
- print(user1.get_email())
- user1.change_email("sarah_help_me@gmail.com")
- print(user2)
- print(user2.__eq__(user1))
- book1 = Book("Coraline", 9780380807345)
- book2 = Book("The Witch-cult in Western Europe", 9781477456965)
- book2.set_isbn(123)
- fict1 = Fiction("Coraline", "Neil Gaiman", 9780380807345)
- print(fict1)
- nonfict1 = Non_Fiction("Society of Mind", "Artificial Intelligence", "beginner", 134567)
- print(nonfict1)
Add Comment
Please, Sign In to add comment