It looks good and readable IMHO. For brownie points, you could:
modify the structure a bit. Not every
LinkedListwill contain books. Similarly, not everyNodein aLinkedListwill have anAuthorName. You could define 4 separate classes :Node,Book,LinkedList, andBookstore(LinkedList).Nodeshould have define adataattribute forNode.define
__str__forNode, which just delegates todata.__str__.define
__str__forBook, which joinsid,bookNameandauthorName.run
autopep8to fix a few minor formatting problems (e.g.self.size+=1->self.size += 1).add a delimiter to
DisplayBook()betweenid,bookNameandauthorName. If the names have spaces, you wouldn't know what the name of the book is.write tests, for example to check that the LinkedList has a correct length or that
DisplayBook()displays the names in correct order. You'd be allowed to use Python lists andsorted()inside the tests.DisplayBook()only prints information and doesn't return anything, so you might have to redirect stdout.move the examples at the end to
main()and check if you're importing the file as a library or running the script. See here.suggest better method names to your teacher. Python classes are
CamelCasebut methods aresnake_case. AlsoDisplayBookseems to suggest that it displays one single book. It could be calleddisplay_books.define a generator for
LinkedList, which would iterate over everyNode. You might not be allowed to use it in your answer, it would make it much easier to use your library, though.