Answer to Question #262300 in Python for Jess

Question #262300

Create a program wherein any user should be able to search books by their title or its author.


1
Expert's answer
2021-11-07T10:12:06-0500
class Book:
    def __init__(self, title, author):
        self.title  = title
        self.author = author
 
allBooks = []


allBooks.append(Book("C++", "Peter Smith"))
allBooks.append(Book('Python', "Nicolas Sparks"))
allBooks.append(Book('Java', "Mary Clark"))


target = input("Enter the title or the author of the book: ").lower()
isFound=False
for b in allBooks:
 if target == b.title.lower():
    isFound=True
    print(b.title+", "+b.author)
 elif target == b.author.lower():
    isFound=True
    print(b.title+", "+b.author)
if isFound==False:
     print("Not found")

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