Done?
This commit is contained in:
commit
368e2a271c
9 changed files with 115 additions and 0 deletions
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
10
.idea/MovieRental.iml
generated
Normal file
10
.idea/MovieRental.iml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.13 (MovieRental)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.13 (MovieRental)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (MovieRental)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/MovieRental.iml" filepath="$PROJECT_DIR$/.idea/MovieRental.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
10
main.py
Normal file
10
main.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from media import *
|
||||
from movie import *
|
||||
|
||||
media1 = Media("Star Wars", 1977)
|
||||
media2 = Movie("Drive", 2011, "R", 79)
|
||||
media3 = Movie("Dune", 2011, "R", 81)
|
||||
|
||||
media1.print_details()
|
||||
media2.print_details()
|
||||
media3.print_details()
|
||||
11
media.py
Normal file
11
media.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Media:
|
||||
def __init__(self, title, year):
|
||||
self.year = year
|
||||
self.title = title
|
||||
|
||||
|
||||
def print_details(self):
|
||||
print(f"Media: {self.title}, {self.year}")
|
||||
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