121 views2 pages
13 Jun 2018
School
Course
Professor
The Movie Class
def __str__(self):
"""
-------------------------------------------------------
Creates a formatted string of movie data.
Use: print(movie)
Use: print( "{}".format(movie))
Use: string = str(movie)
-------------------------------------------------------
Returns:
string - the formatted contents of movie (str)
-------------------------------------------------------
"""
# Generate the list of genres as a string.
genres_list = self.genres_string()
string = """Title: {}
Year: {}
Director: {}
Rating: {}
Genres: {}""".format(self.title, self.year, self.director, self.rating,
genres_list)
return string
def __eq__(self, other):
"""
-------------------------------------------------------
Compares this movie against another movie for equality.
Use: movie == other
-------------------------------------------------------
Parameters:
other - other movie to compare to (Movie)
Returns:
result - True if title and year match, False otherwise (boolean)
-------------------------------------------------------
"""
result = (self.title.lower(), self.year) == \
(other.title.lower(), other.year)
return result
def __lt__(self, other):
"""
-------------------------------------------------------
Determines if this movie comes before another movie.
Use: movie < other
-------------------------------------------------------
Parameters:
other - movie to compare to (Movie)
Returns:
result - True if movie precedes other, False otherwise (boolean)
-------------------------------------------------------
"""
result = (self.title.lower(), self.year) < \
(other.title.lower(), other.year)
return result
def __le__(self, other):
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents

Related Questions