199k views
1 vote
within the derived encyclopedia class, define a printinfo() method that overrides the book class' printinfo() method by printing the title, author, publisher, publication date, edition, and number of pages. ex. if the input is:

User Gimby
by
7.5k points

1 Answer

3 votes

Answer:

class Book:

def __init__(self, title, author, publisher, pub_date, edition, pages):

self.title = title

self.author = author

self.publisher = publisher

self.pub_date = pub_date

self.edition = edition

self.pages = pages

def printinfo(self):

print("Title:", self.title)

print("Author:", self.author)

print("Publisher:", self.publisher)

print("Publication Date:", self.pub_date)

print("Edition:", self.edition)

print("Pages:", self.pages)

class Encyclopedia(Book):

def __init__(self, title, author, publisher, pub_date, edition, pages, volume):

Book.__init__(self, title, author, publisher, pub_date, edition, pages)

self.volume = volume

def printinfo(self):

print("Title:", self.title)

print("Author:", self.author)

print("Publisher:", self.publisher)

print("Publication Date:", self.pub_date)

print("Edition:", self.edition)

print("Pages:", self.pages)

print("Volume:", self.volume)

Step-by-step explanation:

In this example, the Encyclopedia class is derived from the Book class and contains an additional attribute, volume, which stores the volume of the encyclopedia. The printinfo() method in the Encyclopedia class overrides the printinfo() method in the Book class by printing the same information as well as the volume of the encyclopedia.

User Vivek Padhye
by
6.0k points