Create a program wherein any user should be able to search books by their title or its author.
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")
Comments
Leave a comment