f | def fix(n): | f | def fix(n): |
| | | |
n | def dec(fun): | n | def decorator(fun): |
| | | |
| def newfun(*args, **kwargs): | | def newfun(*args, **kwargs): |
n | pos_args = [round(_, n) if isinstance(_, float) else _ for _ in args] | n | new_args = [round(item, n) if isinstance(item, float) else item for item in args] |
| named_args = {key: round(value, n) if isinstance(value, float) else value for (key, value) in kwargs.items()} | | new_kwargs = {k: round(v, n) if isinstance(v, float) else v for (k, v) in kwargs.items()} |
| res = fun(*pos_args, **named_args) | | ret = fun(*new_args, **new_kwargs) |
| return round(res, n) if isinstance(res, float) else res | | return round(ret, n) if isinstance(ret, float) else ret |
| return newfun | | return newfun |
t | return dec | t | return decorator |