Publication Class Hierarchy

Implement a class Publication and then define child classes Book, Magazine, Newspaper, each with additional attributes like title and author for books, title and issue for magazines, and title and date for newspapers. Implement methods to print the details.

Example 1:
Input: publication = Book("1984", "George Orwell")
Output: Title: 1984, Author: George Orwell
Example 2:
Input: publication = Newspaper("The Times", "2023-08-02")
Output: Title: The Times, Date: 2023-08-02

Use inheritance to create child classes and override the method to return the specific details for each publication type.

class Publication:
    def details(self):

class Book(Publication):
    def __init__(self, title, author):
        self.title = title = author

    def details(self):
        return f"Title: {self.title}, Author: {}"

class Magazine(Publication):
    def __init__(self, title, issue):
        self.title = title
        self.issue = issue

    def details(self):
        return f"Title: {self.title}, Issue: {self.issue}"

class Newspaper(Publication):
    def __init__(self, title, date):
        self.title = title = date

    def details(self):
        return f"Title: {self.title}, Date: {}"

publication = Book("1984", "George Orwell")

publication = Newspaper("The Times", "2023-08-02")

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!