Done?
This commit is contained in:
commit
368e2a271c
9 changed files with 115 additions and 0 deletions
47
movie.py
Normal file
47
movie.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import string
|
||||
from dataclasses import dataclass
|
||||
from media import *
|
||||
|
||||
|
||||
class Movie(Media):
|
||||
def __init__(self, title, year, parental_rating, rating):
|
||||
self.parental_rating = parental_rating
|
||||
self.rating = rating
|
||||
|
||||
super().__init__(title, year)
|
||||
|
||||
def movie_ratings(self, title, year, parental_rating, rating, imdb_rating):
|
||||
self.title = title
|
||||
self.year = year
|
||||
self.parental_rating = parental_rating
|
||||
self.rating = imdb_rating * 10
|
||||
|
||||
def __eq__(self, obj):
|
||||
return (isinstance(obj, Movie) and
|
||||
self.title == obj.title and
|
||||
self.year == obj.year and
|
||||
self.parental_rating == obj.parental_rating and
|
||||
self.rating == obj.rating)
|
||||
|
||||
def compare_to(self, other):
|
||||
if other is None:
|
||||
return 1
|
||||
elif self.rating > other.rating:
|
||||
return 1
|
||||
elif self.rating < other.rating:
|
||||
return -1
|
||||
else:
|
||||
return 0
|
||||
|
||||
# Here if I didn't use total_ordering, I would need to complete the logic.
|
||||
# I think it will work exactly as your CompareTo logic.
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.title, self.year, self.parental_rating, self.rating))
|
||||
|
||||
def __str__(self):
|
||||
return f"Movie: {self.title}, {self.year}, Parental Rating: {self.parental_rating}, IMDB Rating: {round(self.rating / 10, 1)}"
|
||||
|
||||
def print_details(self):
|
||||
print(f"Movie: {self.title}, {self.year}, Parental Rating: {self.parental_rating}, IMDB Rating: {round(self.rating / 10, 1)}")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue