0
def searchBooksByAuthor(self, author=None):
    list_1 = [] # search book given the name and surname of the author
    if author is None:
        author_name = input("Give name and surname of the author: ")
        for book in self.content:
            if author_name in str(book):
                list_1.append(book)
        return print(f"The author: {author_name} has written: {lista}")  


if __name__=="__main__":
    bk = bs.searchBooksByAuthor()
    if bk:
        print("The books found are:")
        for b in bk:
            print("\t",b)
    else: print("** There are no such books**")      

TERMINAL:

Give name and surname of the author: Francois Chollet

The author: Francois Chollet has written: [
Book title: Deep Learning with Python from Francois Chollet (2017). Price: 30.2 ISBN: 1617284433]
** There are no such books**  <------ WHY THIS POP UP ??? THANK YOU

i tries everything but i cant figure it out

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    `print()` doesn't return anything, so your function always returns `None`, not an indication of whether there are any books. – Barmar Feb 07 '23 at 18:14
  • You should use `return lista` – Barmar Feb 07 '23 at 18:14
  • 1
    Unrelated, but: you should unindent your first for loop, and everything after it. (Otherwise, when an `author` is provided, that function won't run any code!) Instead, have an `else` clause that produces the `author_name` from `author`. – wizzwizz4 Feb 07 '23 at 18:15
  • The function shouldn't print anything at all. The caller expects it to return the list of books, and it prints them. – Barmar Feb 07 '23 at 18:18
  • 1
    Does this answer your question? [What is the formal difference between "print" and "return"?](https://stackoverflow.com/questions/7664779/what-is-the-formal-difference-between-print-and-return) – 001 Feb 07 '23 at 18:20
  • It shouldn't be your function's job at all to prompt for an author. If your program doesn't already have one, prompt first, then pass the result as a required argument to `searchBooksByAuthor`. – chepner Feb 07 '23 at 18:48

0 Answers0