assignment dy 8 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. class LibraryBook:
  2. def __init__(self, title, author, isbn, year_published):
  3. self.title = title
  4. self.author = author
  5. self.isbn = isbn
  6. self.year_published = year_published
  7. self.available = True
  8. def borrow(self):
  9. if self.available:
  10. self.available = False
  11. print(f"You have borrowed '{self.title}' by {self.author}.")
  12. else:
  13. print(f"Sorry, '{self.title}' is currently not available.")
  14. def return_book(self):
  15. if not self.available:
  16. self.available = True
  17. print(f"You have returned '{self.title}'. Thank you!")
  18. else:
  19. print(f"'{self.title}' was not borrowed.")
  20. def detail(self):
  21. print(f"Title: {self.title}")
  22. print(f"Author: {self.author}")
  23. print(f"ISBN: {self.isbn}")
  24. print(f"Year Published: {self.year_published}")
  25. print(f"Available: {'Yes' if self.available else 'No'}")
  26. book1 = LibraryBook("To Kill a Mockingbird", "Harper Lee", "978-0-06-112008-4", 1960) # type: ignore
  27. book2 = LibraryBook("1984", "George Orwell", "978-0-452-28423-4", 1949) # type: ignore
  28. book3 = LibraryBook("Pride and Prejudice", "Jane Austen", "978-0-19-953556-9", 1813) # type: ignore
  29. #book1
  30. detail = book1.detail()
  31. borrow = book1.borrow()
  32. detail = book1.detail()
  33. return_book = book1.return_book()
  34. detail = book1.detail()
  35. #book2
  36. detail = book2.detail()
  37. borrow = book2.borrow()
  38. detail = book2.detail()
  39. return_book = book2.return_book()
  40. detail = book2.detail()
  41. #book3
  42. detail = book3.detail()
  43. borrow = book3.borrow()
  44. detail = book3.detail()
  45. return_book = book3.return_book()
  46. detail = book3.detail()
  47. #newattribute
  48. def availability(self):
  49. if self.available:
  50. print("True")
  51. elif self.borrow:
  52. print("False")
  53. if self.return_book:
  54. print("True")
  55. if self.already_borrowed:
  56. print("This book is already borrowed.")