Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #class=> Library
- #Layer of Encapsulation=> Display available books, lend a book, add a book
- #class=> Customer
- #Layer of abstraction => request a book, return a book
- print("\t\t\tBLESSING'S LIBRARY")
- print( )
- class Library():
- def __init__(self,list_of_books):
- self.availablebooks = list_of_books
- def display_available_books(self):
- print( )
- print("Available Books: ")
- for book in self.availablebooks:
- print(book)
- def lend_a_book(self,requestedBook):
- print( )
- if requestedBook in self.availablebooks:
- print(f"You have borrowed {requestedBook} ")
- self.availablebooks.remove(requestedBook)
- else:
- print("Sorry the book you requested isn't available")
- def add_a_book(self, returnedBook):
- self.availablebooks.append(returnedBook)
- print("You have returned the book. Thank You!")
- class Customer():
- def request_a_book(self):
- print("Enter the book you want to request: ")
- self.book = input( )
- return self.book
- def return_a_book(self):
- print("Enter the name of the book you are returning : ")
- self.book = input( )
- return self.book
- library = Library(["K.A Stroud Algebra", "Pressupositional Apologetics","V.K Mheta","How to think Like a Computer Scientist", "A Complete Introduction to Python", "Advanced Engineering Mathematics", "Introduction to Object-Oriented Programming", "Intoduction to Numpy"])
- customer = Customer()
- while True:
- print("Press 1 to display the available books")
- print("Press 2 to request a book")
- print("Press 3 to return a book")
- print("Press 4 to exit")
- useroption = int(input( ))
- if useroption == 1:
- library.display_available_books()
- elif useroption ==2:
- request = customer.request_a_book()
- library.lend_a_book(request)
- elif useroption ==3:
- returnedBook = customer.return_a_book()
- library.add_a_book(returnedBook)
- elif useroption ==4:
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement