diff --git a/app/main.py b/app/main.py index 6d375672..99f0ce0f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,25 +1,72 @@ +from __future__ import annotations from abc import ABC class IntegerRange: - pass + def __init__(self, min_amount: int, max_amount: int) -> None: + self.min_amount = min_amount + self.max_amount = max_amount + + def __get__(self, instance: any, owner: any) -> tuple: + return self.min_amount, self.max_amount + + def __set__(self, instance: any, value: int) -> None: + if not isinstance(value, int): + raise TypeError("Only integers are allowed") + if value not in range(self.min_amount, self.max_amount + 1): + raise ValueError( + f"Value must be between " + f"{self.min_amount} and {self.max_amount}" + ) + setattr(instance, self.name, value) + + def __set_name__(self, owner: any, name: any) -> None: + self.name = f"_{name}" class Visitor: - pass + def __init__(self, + name: str, + age: int, + weight: int, + height: int) -> None: + self.name = name + self.age = age + self.weight = weight + self.height = height class SlideLimitationValidator(ABC): - pass + def __init__(self, + age: int, + weight: int, + height: int + ) -> None: + self.age = age + self.weight = weight + self.height = height class ChildrenSlideLimitationValidator(SlideLimitationValidator): - pass + age = IntegerRange(4, 14) + weight = IntegerRange(20, 50) + height = IntegerRange(80, 120) class AdultSlideLimitationValidator(SlideLimitationValidator): - pass + age = IntegerRange(14, 60) + weight = IntegerRange(50, 120) + height = IntegerRange(120, 220) class Slide: - pass + def __init__(self, name: str, limitation_class: type) -> None: + self.name = name + self.limitation_class = limitation_class + + def can_access(self, visitor: Visitor) -> bool: + try: + self.limitation_class(visitor.age, visitor.weight, visitor.height) + return True + except ValueError: + return False