Library Management System in python OOPs Concept
class Library:
def__init__(self,listofbooks,libraryname):
self.lst = listofbooks
self.name = libraryname
def displaybook(self):
return f"\t\t\t\tWelcome to {self.name} \
\navaliable books are -\n {self.lst}"
def lendbook(self,lendname,bookname):
if bookname in lst and bookname not in d:
print(f"{bookname} lend to {lendname}")
d.__setitem__(bookname,lendname)
elif bookname in d:
lst.remove(bookname)
print("Book is not available lend to-",d[bookname],"\nwe only have-",lst)
else:
print("Book is not in the library we only have-",lst)
def addbook(self,bookname):
print("Book added successfully in the library")
lst.append(bookname)
def returnbook(self,returenername,bookname):
if returenername in d[bookname]:
print("Book successfully returned")
d.pop(bookname)
else :
print("Wrong data")
if __name__=='__main__':
lst = ['Python','Science','Mathematics',
'Social Science']
l = Library(lst,'World Library')
print(l.displaybook())
d = {"Python":"Ravi Dubey"}
exit = 1
while exit:
print("For Lending book press 1\nFor add book press 2\nFor return book press 3\nFor exit press 4")
n = int(input())
if n==1:
l.lendbook(str(input("Enter your name-")),str(input("Enter book name-")))
elif n==2:
l.addbook(str(input("Enter book name you want to add-")))
elif n==3:
l.returnbook(str(input("Enter your name-")),str(input("Enter book name-")))
elif n==4:
exit = 0
else:
print("Wrong input")
Video of code is -
Comments
Post a Comment
If you have any doubt you ask me in comment section