Write a Movie
class. It should have the following attributes:
title
: string title of the moviestarring
: list of actors and actresses (strings) in the movieyear
: integer year of releasestars
: number of stars, 0-5genre
: string indicating the genre of the movieIt should have the following methods:
getTitle()
: returns the title of the moviegetStarring()
: returns the list of starring actors and actressesaddActor(actor)
: adds an actor's name to the list of those starringremActor(actor)
: removes the specified actor from the list of those starring (case-insensitive)getStars()
: returns the number of stars for the movieNo import
statements allowed.
In [ ]:
In [ ]:
assert Movie
In [ ]:
m = Movie(title = "Avengers: Infinity War", year = 2018, stars = 4.9, genre = "Action/Adventure", "Chris Evans", "Robert Downey, Jr.", "Scarlett Johansson")
assert m.title == "Avengers: Infinity War"
assert m.year == 2018
assert set(m.starring) == set(["Chris Evans", "Robert Downey, Jr.", "Scarlett Johansson"])
assert m.genre == "Action/Adventure"
assert int(m.stars) == 4
In [ ]:
m = Movie(title = "Avengers: Untitled", year = 2019, stars = 4.95, genre = "Action/Adventure", "Person 1", "Person 2", "Unnamed Avenger", "Who now?")
assert m.getTitle() == "Avengers: Untitled"
assert set(m.getStarring()) == set(["Person 1", "Person 2", "Unnamed Avenger", "Who now?"])
assert int(m.getStars()) == int(4.95)
m.addActor("Probably Robert Downey")
assert set(m.getStarring()) == set(["Person 1", "Person 2", "Unnamed Avenger", "Who now?", "Probably Robert Downey"])
m.remActor("person 2")
assert set(m.getStarring()) == set(["Person 1", "Unnamed Avenger", "Who now?", "Probably Robert Downey"])
Write a MovieTracker
class. It will be used to track multiple Movie
instances simultaneously. It should have the following attributes:
movies
: a list of Movie
instancesIt should have the following methods:
addMovie(movie)
: adds a new Movie
object to its internal list of moviesremMovie(movie)
: removes the specified Movie
object; equality is determined by movie title (case-insensitive)avgRating()
: returns the average rating (stars) of all the movies in the trackergetGenre(genre)
: returns all the movies in the tracker that belong to the specified genre (case-insensitive), otherwise returns an empty listratingAtLeast(rating)
: returns all the movies in the tracker with at least the specified rating, otherwise returns an empty list
In [ ]:
In [ ]:
assert MovieTracker
In [ ]:
m1 = Movie(title = "Avengers: Infinity War", year = 2018, stars = 4.9, genre = "Action/Adventure", "Chris Evans", "Robert Downey, Jr.", "Scarlett Johansson")
mt = MovieTracker()
mt.addMovie(m1)
assert len(mt.movies) == 1
assert mt.avgRating() == 4.9
assert len(mt.ratingAtLeast(5.0)) == 0
In [ ]:
m1 = Movie(title = "Avengers: Infinity War", year = 2018, stars = 4.9, genre = "Action/Adventure", "Chris Evans", "Robert Downey, Jr.", "Scarlett Johansson")
m2 = Movie(title = "Avengers: Untitled", year = 2019, stars = 4.95, genre = "Action/Adventure", "Person 1", "Person 2", "Unnamed Avenger", "Who now?")
mt = MovieTracker()
mt.addMovie(m1)
mt.addMovie(m2)
assert len(mt.movies) == 2
assert mt.avgRating() == 4.925
assert len(mt.ratingAtLeast(4)) == 2
assert len(mt.getGenre("action/adventure")) == 2
mt.remMovie("avengers: untitled")
assert len(mt.movies) == 1
In this part, you'll write children classes of the Movie
class based on genre. Create at least three children classes that specify a genre in their name (e.g. ComedyMovie
, DramaMovie
, etc).
Make sure to write a constructor for each class, but otherwise no need to override any existing functionality or add new functionality.
In [ ]: