horozov86

Unit_tests_movie_25.07.2023

Aug 2nd, 2023
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. class Movie:
  2.     def __init__(self, name: str, year: int, rating: float):
  3.         self.name = name
  4.         self.year = year
  5.         self.rating = rating
  6.         self.actors = []
  7.  
  8.     @property
  9.     def name(self):
  10.         return self.__name
  11.  
  12.     @name.setter
  13.     def name(self, value):
  14.         if value == '':
  15.             raise ValueError("Name cannot be an empty string!")
  16.         self.__name = value
  17.  
  18.     @property
  19.     def year(self):
  20.         return self.__year
  21.  
  22.     @year.setter
  23.     def year(self, value):
  24.         if value < 1887:
  25.             raise ValueError("Year is not valid!")
  26.         self.__year = value
  27.  
  28.     def add_actor(self, name: str):
  29.         if name not in self.actors:
  30.             self.actors.append(name)
  31.         else:
  32.             return f"{name} is already added in the list of actors!"
  33.  
  34.     def __gt__(self, other):
  35.         if self.rating > other.rating:
  36.             return f'"{self.name}" is better than "{other.name}"'
  37.         else:
  38.             return f'"{other.name}" is better than "{self.name}"'
  39.  
  40.     def __repr__(self):
  41.         return f"Name: {self.name}\n" \
  42.                f"Year of Release: {self.year}\n" \
  43.                f"Rating: {self.rating:.2f}\n" \
  44.                f"Cast: {', '.join(self.actors)}"
Add Comment
Please, Sign In to add comment