In: Computer Science
Design a Python example that includes the following
Basic concepts:
two of the advanced concepts: Encryption / Decryption, Lists / Dictionaries
Please leave a Description of the program
class library:
books={1:"The fault in our stars",2:"The Alchemist",3:"The jungle book",4:"Rd sharma",5:"Science everyday",6:"gulliver's travel",7:"Kissing booth",8:"The power of subconsious mind"}
lend={1:"khushi dubey"}
avail={2:"The Alchemist",3:"The jungle book",4:"Rd sharma",5:"Science everyday",6:"gulliver's travel",7:"Kissing booth",8:"The power of subconsious mind"}
def disp(cls):
for item,var in cls.books.items():
print(item,var)
print("\n")
def addbook(cls,key,name):
v=0
for items in cls.books:
if key==items:
print("Book cannot be added.Change the key value\n")
v=1
if v==0:
cls.books.update({key:name})
print("Book added to the library\n")
print("\n")
def lend_book(cls,book_no,person):
count=0
i=0
for item,var in cls.lend.items():
if var==person:
count=count+1
elif item==book_no:
i=1
if count>=2:
print("You cannot lend more than two books.Limit over!\n")
elif i==1:
print("This book is already lended.Choose some other book\n")
else:
cls.lend.update({book_no:person})
for item,var in cls.books.items():
if book_no!=item:
x=cls.books.get(item)
cls.avail.update({item:x})
for (key) in set(cls.avail) & set(cls.lend):
del cls.avail[key]
print("\n")
def return_book(cls,book_no,person):
a=0
for item in list(cls.lend.keys()):
if item==book_no:
del cls.lend[item]
print("Book returned\n")
a=1
if a==1:
for item,var in cls.books.items():
if book_no==item:
x=cls.books.get(item)
cls.avail.update({item:x})
else:
print("book already returned\n")
def availi(cls):
print("Books available are:\n")
for item,var in cls.avail.items():
print(item,var)
if __name__=='__main__':
b=library()
print("Welcome to online library\n")
while True:
user_input=int(input("choose 1 to display the books\n2 to add a book\n3 to lend a book according to the availability\n4 to return the book\n"))
if user_input==1:
b.disp()
elif user_input==2:
book_id=int(input("enter book_id\n"))
book_name=input("enter book name\n")
b.addbook(book_id,book_name)
elif user_input==3:
b.availi()
name=input("Enter your name\n")
book_no=int(input("Enter book_id from the available books above\n"))
b.lend_book(book_no,name)
elif user_input==4:
name=input("Enter your name\n")
book_no=int(input("Enter book_id you have to return\n"))
b.return_book(book_no,name)
else:
print("wrong input\n")
THIS IS A PROGRAM FOR A LIBRARY SYSTEM.ONE CAN ADD, DISPLAY,LEND AND RETURN A BOOK .ONE PERSON CANNOT LEND MORE THAN 2 BOOKS.HERE FOR LOOP, DICTIONARY AND CONDITIONAL STATEMENTS ARE USED.