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
- import random
- import datetime
- today = datetime.datetime.now()
- year = today.year
- month = today.month + 2
- day = today.day
- deadline = datetime.datetime(year, month, day)
- print("\t\t\tBLESSING'S LIBRARY")
- print( )
- StudentDetails = { }
- class Library():
- def __init__(self, dict_of_books):
- self.availablebooks = dict_of_books
- def display_available_books(self):
- print( )
- print("Available Books: ")
- print("______________________________________")
- for book in self.availablebooks:
- print("\t\t\t", book)
- print("_______________________________________")
- def lend_a_book(self,requestedBook):
- print( )
- global deadline
- my_deadline = deadline.strftime("%A, %B %d, %Y")
- if requestedBook in self.availablebooks and self.availablebooks[requestedBook] >=1:
- print(f"You have borrowed \"{requestedBook}\".")
- print(f"The deadline for submission is on {my_deadline}")
- print()
- self.availablebooks[requestedBook]-=1
- elif requestedBook not in self.availablebooks:
- print(f"Sorry \"{requestedBook}\" not available. Modifications will be made latter")
- print()
- elif requestedBook in self.availablebooks and self.availablebooks[requestedBook]==0:
- print(f"Sorry \"{requestedBook}\" is out of stock. Check up later")
- print()
- def add_a_book(self, returnedBook):
- self.availablebooks[returnedBook]+=1
- print(f"You have returned {returnedBook}. Thank You!")
- class Customer():
- def request_a_book(self):
- print("Enter the book you want to request: ")
- self.book = input( ).title()
- return self.book
- def return_a_book(self):
- print("Enter the name of the book you are returning : ")
- self.book = input( ).title()
- return self.book
- library = Library({"Lord Of The Rings": 5,"The Colour Of Magic":12,"A Game Of Thrones":25, "The Fellowship Of The Ring":16,"Pride And Prejudice":10,
- "Fifty Shades Of Grey":4,"The Hating Game":6,"Vision White":14,"Gone With The Wind":2,"The Thorn Birds":7,
- "The Calculating Stars":3,"Semiosis":13,"Space Opera":7,"The Book Of M":11,"The Gone World":13,"Blackfish City":15,
- "Into Thin Air":8,"Into The World":12,"Treasure Island":5,"Journey To The Centre Of The Earth":6, "Heart of Darkness":4,
- "The Power Of Positive Thinking":3,"Think And Grow Rich":2, "You Are A Badass":17, "You Can Heal Your Life":16})
- customer = Customer()
- while True:
- print("Press 1 to Create Account")
- print("Press 2 to login")
- print("Press 3 to exit")
- print()
- inp = int(input( ))
- if inp == 1:
- accountID = random.randint(100000, 999999)
- def CreateAccount():
- name = input("Enter your Name: ")
- email = input("Enter your Email Address ")
- global accountID
- global StudentDetails
- StudentDetails[name] = [accountID, email]
- return True
- CreateAccount = CreateAccount()
- if CreateAccount is True:
- print("Account Creation Successful")
- print(f"Your Account ID is {accountID}")
- print()
- 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 return to previous menu")
- print()
- useroption = int(input())
- if useroption ==1:
- library.display_available_books()
- print()
- 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:
- break
- else:
- print("Account Creation Failed")
- elif inp == 2:
- def login():
- name = input("Enter your name:")
- email = input("Enter your email address: ")
- accountid = (input("Enter your account Id: "))
- global StudentDetails
- if name in StudentDetails:
- if email and accountid in name:
- return True
- else:
- return False
- else:
- return False
- login = login()
- if login is True:
- print("Login Successful")
- print()
- 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 return to previous menu")
- print()
- useroption = int(input())
- if useroption == 1:
- library.display_available_books()
- print()
- 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:
- break
- else:
- print("Login not Successful. Invalid Name or Account ID")
- elif inp ==3:
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement