Create a module called library. This module should include two classes as well a
ID: 3761666 • Letter: C
Question
Create a module called library. This module should include two classes as well as methods for each. The provided file library_test.py will use the contents of library.py. Do not edit library_test.py for your submission, though you are free to comment out lines using parts of library.py that you have not implemented yet. The contents of library.py should be as follows:
class Library: A Library object stores multiple Book objects and has methods to return statistics about those books. When printed, the object should list all of the books it contains in alphabetical order by author (as listed. You do not need to split into first and last names).
def add_book(self, book) This method takes in either a line of text or a book object. If the input is a line of text, then it creates a new Book object out of it. The line of text will be formatted as are the lines in library.txt and should be parsed as needed to form a Book object. The object (whether given or created) is then stored inside the library. def get_authors(self) This method returns a list of all the authors who have works contained in the library. No author should appear more than once.
def get_books_per_author(self) This method returns a dictionary. Each author should be a key in the dictionary. The value for each author should be the number of books by that author in the library. class Book ABook object stores the author and title of a book. When printed, the object should display both the title and author of the book. The constructor should take in two arguments: the title of the book and the author of the book.
I dont want the solution, but as an explanation of where and how to start, tips and what you would recommend on how to go about this. Thanks again!
Explanation / Answer
Module creation:
def command can be used to create a module as follows:
def library1():
# further commands have to be indented
# more library commands here
# end of indenting denotes the end of module and start of the next module
The standard and built in modules can be imported using import statements
like
import sys
etc
Once you create the basic library class, other classes can be inherited from it
class libraryClass:
def joinNewMember():
def cancelMembership():
def updateMemberDetails():
# change of address etc
def add_book(self, book):
# here receive input from the user
# store those in to the python class methods defined
def get_authors(self):
# details of each and every author
def get_books_per_author(self):
# key for the dictionary = the author
# author1 = number of books written by author1
# author2 = number of books written by author2
# author3 = number of books written by author3
# author4 = number of books written by author4
# author5 = number of books written by author5
# author6 = number of books written by author6
# author7 = number of books written by author7
class bookClass:
# stores title and author each book
# for example: Title: Artificial Intelligence , a modern Approach, Author: Stuart Russell, Peter Norvig
# Title: C Programming, Author: Kenningham Ritchie
def constructorBook():
# title
# Author
# declare methods
def borrowBook():
def returnBook():
def renewBook():
def payFine():
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.