From be97b8b89b8641f16f39d44f9c7f57b33bdb94f9 Mon Sep 17 00:00:00 2001 From: Felix Poslushnyi Date: Sun, 8 Sep 2024 21:56:27 +0300 Subject: [PATCH] Apply three changes --- app/main.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/app/main.py b/app/main.py index bd9efd3..6627766 100644 --- a/app/main.py +++ b/app/main.py @@ -21,7 +21,10 @@ def validate(self, value: int) -> None: raise TypeError("Expected value to be an int") if value < self.min_amount or value > self.max_amount: - raise ValueError("Value error !!!") + raise ValueError( + f"Expected {value!r} to be no more than {self.min_amount}" + f"and less than {self.max_amount}." + ) class Visitor: @@ -55,32 +58,19 @@ class Slide: def __init__( self, name: str, - limitation_class: ChildrenSlideLimitationValidator - | AdultSlideLimitationValidator + limitation_class: type[SlideLimitationValidator] ) -> None: self.name = name self.limitation_class = limitation_class def can_access(self, visitor: Visitor) -> None: - has_access = False - if visitor.age <= 60 and visitor.age >= 14: - if self.limitation_class is None: - self.limitation_class = AdultSlideLimitationValidator - - if visitor.age <= 14 and visitor.age >= 4: - if self.limitation_class is None: - self.limitation_class = ChildrenSlideLimitationValidator - - if self.limitation_class is not None: - try: - self.limitation_class( - visitor.age, - visitor.height, - visitor.weight - ) - except ValueError: - has_access = False - else: - has_access = True - - return has_access + try: + self.limitation_class( + visitor.age, + visitor.height, + visitor.weight + ) + except ValueError: + return False + else: + return True