def decorator_function(func_to_be_called): def wrapper(*args, **kwargs): print("Some text before calling function") func_to_be_called(*args, **kwargs) print("Some text after calling function") return wrapper @decorator_function def print_function(text): print("Your text is:", text) # print_function("Hello") #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from datetime import datetime def decorator_function(func_to_be_called): def wrapper(*args, **kwargs): print("Some text before calling function") func_to_be_called(*args, **kwargs) print("Some text after calling function") return wrapper def time_sum(func): def wrapper(text): d1 = datetime.now() print("Time before calling", d1) func(text) d2 = datetime.now() print("Time after calling", d2) print(d2 - d1) return wrapper @time_sum @decorator_function def print_function(text): print("Your text is:", text) # print_function("Hello") #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def decorator_function(func_to_be_called): def wrapper(text): print("Some text before calling function") result = func_to_be_called(text) print("Some text after calling function") return result return wrapper @decorator_function def print_function(text): return "Your text is: " + text # print(print_function("Hello")) def decorator(func): def wrapper(a, b): if a < 0 or b < 0: print("YES") result = func(a, b) return result return wrapper # Connect decorator please @decorator def main(a, b): return a + b # x, y = [int(x) for x in input().split()] # print(main(3, 6)) # print(main(-3, 6)) def test_exc_1(a, b): res = 0 try: print(a/b) except Exception as e: print("Error:", Exception) def test_exc_2(a, b): res = 0 try: print(a/b) except ZeroDivisionError: print("Error") except: print("Something another") def test_exc_3(): try: a, b = int(input()), int(input()) print(a +b) except: print("error") finally: print("end") def test_exc_4(): try: a, b = int(input()), int(input()) print(a + b) except: print("error") else: print("end") def test_raise(): a, b = int(input()), int(input()) if a + b == 3: raise RuntimeError("Oops, sum is 3") else: print(a + b)