Answer to Question #261898 in Python for Jess

Question #261898

Create a library management system wherein any library member should be able to search books by their title or its author.


1
Expert's answer
2021-11-07T01:57:25-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS