In: Computer Science
Language: Python
Implement the Book class as demonstrated below. You should not change the Book methods and implementation as provided. The docstrings in the template contain descriptions of each method.
>>> b=Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001)
>>> b
Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001)
>>> str (b)
' Code : Charles Ptzold: Computing: 2001 '
>>> b. getTitle ( )
' Code '
>>> b. getAuthor()
' Charles Ptzold'
>>> b. getPublicationYear( )
2001
>>> b*10
[Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) , Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001)]
>>> b2=Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001)
True
>>> b3=Book( ' Code' , 'Charles Ptzold' 'Computing' , 2003)
False
__________________________________________________________________________
import random
class Book(object):
def __init__(self,title='',author='', genre='', yearOfPublication=0):
'constructor.'
pass
def getTitle(self):
'get book title'
pass
def getAuthor(self):
'get book author'
pass
def getGenre(self):
'get book genre'
pass
def getPublicationYear(self):
'get publication year'
pass
def __mul__(self,count):
'makes copies of the book and returns a list of all the copies'
pass
def __eq__(self,other):
'Compares two books. returns True if all properites of a book are the same, False otherwise'
pass
def __str__(self):
'string representation of Book'
pass
def __repr__(self):
'python representation of Book'
pass
import random
class Book(object):
def __init__(self,title='',author='', genre='',
yearOfPublication=0):
'constructor.'
self.title=title
self.author=author
self.genre=genre
self.yearOfPublication=yearOfPublication
def getTitle(self):
'get book title'
return self.title
def getAuthor(self):
'get book author'
return self.author
def getGenre(self):
'get book genre'
return self.genre
def getPublicationYear(self):
'get publication year'
return self.yearOfPublication
def __mul__(self,count):
'makes copies of the book and returns a list of all the
copies'
l=[]
for i in range(count):
l.append(Book(self.title,self.author,self.genre,self.yearOfPublication))
return l
def __eq__(self,other):
'Compares two books. returns True if all properites of a book are
the same, False otherwise'
if(self.title==other.getTitle()):
if(self.author==other.getAuthor()):
if(self.genre==other.getGenre()):
if(self.yearOfPublication==other.getPublicationYear()):
return True
return False
def __str__(self):
'string representation of Book'
return self.title+" : "+self.author+": "+self.genre+":
"+str(self.yearOfPublication)
def __repr__(self):
'python representation of Book'
return "Book ( '" +self.title+"' , '"+self.author+"'
'"+self.genre+"' , "+str(self.yearOfPublication)+")"
Screenshots:
The screenshots are attached below for reference.
Please follow them for output and proper indentation.
Please upvote my answer. Thank you.