Movie Genres Hierarchy

Create a class Movie with attributes like title, director, and release year. Then define child classes for different genres like ActionMovie, HorrorMovie, ComedyMovie, each having a unique method genre_description that returns a description of the genre.

Example 1:

Input: ActionMovie('Die Hard', 'John McTiernan', 1988) 
Output: "Die Hard is an action movie directed by John McTiernan, released in 1988. Action movies usually involve a story of good vs evil with plenty of physical action and stunts."

Example 2:

Input: ComedyMovie('Superbad', 'Greg Mottola', 2007) 
Output: "Superbad is a comedy movie directed by Greg Mottola, released in 2007. Comedy movies primarily focus on humor to engage the audience."

Implement the Movie class with basic attributes like title, director, and release year. Then, define the genre_description method in each of the child classes that returns the respective genre description.

class Movie:
    def __init__(self, title, director, release_year):
        self.title = title
        self.director = director
        self.release_year = release_year

class ActionMovie(Movie):
    def genre_description(self):
        return f"{self.title} is an action movie directed by {self.director}, released in {self.release_year}. Action movies usually involve a story of good vs evil with plenty of physical action and stunts."

class HorrorMovie(Movie):
    def genre_description(self):
        return f"{self.title} is a horror movie directed by {self.director}, released in {self.release_year}. Horror movies aim to create a sense of fear, panic, and alarm for the audience."

class ComedyMovie(Movie):
    def genre_description(self):
        return f"{self.title} is a comedy movie directed by {self.director}, released in {self.release_year}. Comedy movies primarily focus on humor to engage the audience."

# Test the classes
movie1 = ActionMovie('Die Hard', 'John McTiernan', 1988)
print(movie1.genre_description())

movie2 = ComedyMovie('Superbad', 'Greg Mottola', 2007)
print(movie2.genre_description())

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!