Create a library management system wherein any library member should be able to search books by their title or its author.
search_for = input("Type the keyword: ").lower()
# Python3 code here creating class
class books:
def __init__(self, name, author, publication, subject):
self.name = name.lower()
self.author = author.lower()
self.publication = publication
self.subject = subject.lower()
# creating list
list = []
# appending instances to list
list.append( books("The Judge's List", "John Grisham", "10/2021", "fiction"))
list.append( books('The Wish', "Nicolas Sparks", "09/2021", "drama"))
result = []
for obj in list:
if search_for in obj.name:
result.append(obj.name)
if search_for in obj.author:
result.append(obj.name)
if search_for in obj.subject:
result.append(obj.name)
if len(result) < 1:
print("Not found")
else:
print(result)
Comments
Leave a comment