Advertisement
Blessing988

Untitled

Apr 2nd, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. #class=> Library
  2. #Layer of Encapsulation=> Display available books, lend a book, add a book
  3. #class=> Customer
  4. #Layer of abstraction => request a book, return a book
  5.  
  6. print("\t\t\tBLESSING'S LIBRARY")
  7. print( )
  8.  
  9.  
  10.  
  11.  
  12. class Library():
  13.     def __init__(self,list_of_books):
  14.         self.availablebooks = list_of_books
  15.  
  16.     def display_available_books(self):
  17.         print( )
  18.         print("Available Books: ")
  19.         for book in self.availablebooks:
  20.             print(book)
  21.            
  22.        
  23.  
  24.     def lend_a_book(self,requestedBook):
  25.         print( )
  26.         if requestedBook in self.availablebooks:
  27.             print(f"You have borrowed {requestedBook} ")
  28.             self.availablebooks.remove(requestedBook)
  29.         else:
  30.             print("Sorry the book you requested isn't available")
  31.            
  32.  
  33.     def add_a_book(self, returnedBook):
  34.         self.availablebooks.append(returnedBook)
  35.         print("You have returned the book. Thank You!")
  36.        
  37.        
  38.  
  39. class Customer():
  40.  
  41.     def request_a_book(self):
  42.         print("Enter the book you want to request: ")
  43.         self.book = input( )
  44.         return self.book
  45.  
  46.     def return_a_book(self):
  47.         print("Enter the name of the book you are returning : ")
  48.         self.book = input( )
  49.         return self.book
  50.  
  51. 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"])
  52. customer = Customer()
  53.  
  54. while True:
  55.     print("Press 1 to display the available books")
  56.     print("Press 2 to request a book")
  57.     print("Press 3 to return a book")
  58.     print("Press 4 to exit")
  59.    
  60.  
  61.     useroption = int(input( ))
  62.    
  63.     if useroption == 1:
  64.         library.display_available_books()
  65.     elif useroption ==2:
  66.         request = customer.request_a_book()
  67.         library.lend_a_book(request)
  68.     elif useroption ==3:
  69.         returnedBook = customer.return_a_book()
  70.         library.add_a_book(returnedBook)
  71.     elif useroption ==4:
  72.         quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement