Advertisement
Guest User

Untitled

a guest
Aug 13th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. from calendar import month_name
  2.  
  3.  
  4. class DVD:
  5. def __init__(self, name: str, id: int, creation_year: int, creation_month: str, age_restriction: int):
  6. self.name = name
  7. self.id = id
  8. self.creation_year = creation_year
  9. self.creation_month = creation_month
  10. self.age_restriction = age_restriction
  11. self.is_rented = False
  12.  
  13. @classmethod
  14. def from_date(cls, id: int, name: str, date: str, age_restriction: int):
  15. separated_dates = cls.separate_date(date)
  16. return cls(name, id, int(separated_dates[2]), month_name[int(separated_dates[1])], age_restriction)
  17.  
  18. def check_if_rented(self):
  19. if self.is_rented is True:
  20. return 'rented'
  21. else:
  22. return 'not rented'
  23.  
  24. @staticmethod
  25. def separate_date(date: str):
  26. date_list = date.split('.')
  27. return date_list
  28.  
  29. def __repr__(self):
  30. return f"{self.id}: {self.name} ({self.creation_month} {self.creation_year})" \
  31. f" has age restriction {self.age_restriction}. Status: {self.check_if_rented()}"
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement