f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
| def __init__(self, n): | | def __init__(self, n): |
| if not 1 <= n <= 16: | | if not 1 <= n <= 16: |
n | raise ValueError('Значение n должно быть от 1 до 16 включите | n | raise ValueError('n должен быть в диапазоне от 1 до 16') |
| льно') | | |
| self.n = n | | self.n = n |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| | | |
| @wraps(func) | | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
| rounded_args = tuple((round(arg, self.n) if isinstance(arg, | | rounded_args = tuple((round(arg, self.n) if isinstance(arg, |
| float) else arg for arg in args)) | | float) else arg for arg in args)) |
t | rounded_kwargs = {k: round(v, self.n) if isinstance(v, float | t | rounded_kwargs = {key: round(value, self.n) if isinstance(va |
| ) else v for k, v in kwargs.items()} | | lue, float) else value for key, value in kwargs.items()} |
| result = func(*rounded_args, **rounded_kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
| if isinstance(result, float): | | if isinstance(result, float): |
| result = round(result, self.n) | | result = round(result, self.n) |
| return result | | return result |
| return wrapper | | return wrapper |