From e8529653514ed9f465e2e5f476d3e6b1734e3c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=83=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=9F=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE?= <124675990+CrazyDuck192@users.noreply.github.com> Date: Tue, 21 Mar 2023 20:37:57 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BB=D0=B0=D1=81=D0=BD=D0=B0=20=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BE=D1=82=D0=B0=20=E2=84=9614=20(=E2=84=9617.18,?= =?UTF-8?q?=2017.20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17.18.py | 22 ++++++++++++++++++++++ 17.20.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 17.18.py create mode 100644 17.20.py diff --git a/17.18.py b/17.18.py new file mode 100644 index 0000000..8901651 --- /dev/null +++ b/17.18.py @@ -0,0 +1,22 @@ +from collections import Counter + +def lower(func): + + def _lower(*args): + args_lower = '' + for arg in args: + args_lower += arg.lower() + y = func(args_lower) + + return y + + return _lower + +@lower +def count(s): + return Counter(s) + +if __name__ == '__main__': + s = 'abcdABCefgGFAB' + g = 'qQQqqwerERwww' + print(count(s, g)) \ No newline at end of file diff --git a/17.20.py b/17.20.py new file mode 100644 index 0000000..1a0794d --- /dev/null +++ b/17.20.py @@ -0,0 +1,48 @@ +def check_type(*typechecker): + + def _check_type(func): + + def __check_type(*args, **kwargs): + + try: + if len(typechecker) != len(args): + raise TypeError('Amounts do not match') + except TypeError: + return TypeError('Amounts do not match') + + try: + for i, t in zip(args, typechecker): + if type(i) != t: + raise TypeError('Types do not match') + except TypeError: + return TypeError('Types do not match') + + y = func(*args, **kwargs) + return y + + return __check_type + + return _check_type + +class TypeError(Exception): + + def __init__(self, msg): + super().__init__() + self.msg = msg + + def __str__(self): + return self.msg + +@ check_type(int, str, tuple) +def func(a, b, c): + return f'| {a} | {b} | {c} |' + + +if __name__ == '__main__': + print(func(22, 'hello', (1, 'hi', 2))) + print(func(22.5, 'hello', (1, 'hi', 2))) + print(func(22,'hello world')) + + + + \ No newline at end of file