test1.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. def decorator_function(func_to_be_called):
  2. def wrapper(*args, **kwargs):
  3. print("Some text before calling function")
  4. func_to_be_called(*args, **kwargs)
  5. print("Some text after calling function")
  6. return wrapper
  7. @decorator_function
  8. def print_function(text):
  9. print("Your text is:", text)
  10. # print_function("Hello")
  11. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. from datetime import datetime
  13. def decorator_function(func_to_be_called):
  14. def wrapper(*args, **kwargs):
  15. print("Some text before calling function")
  16. func_to_be_called(*args, **kwargs)
  17. print("Some text after calling function")
  18. return wrapper
  19. def time_sum(func):
  20. def wrapper(text):
  21. d1 = datetime.now()
  22. print("Time before calling", d1)
  23. func(text)
  24. d2 = datetime.now()
  25. print("Time after calling", d2)
  26. print(d2 - d1)
  27. return wrapper
  28. @time_sum
  29. @decorator_function
  30. def print_function(text):
  31. print("Your text is:", text)
  32. # print_function("Hello")
  33. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. def decorator_function(func_to_be_called):
  35. def wrapper(text):
  36. print("Some text before calling function")
  37. result = func_to_be_called(text)
  38. print("Some text after calling function")
  39. return result
  40. return wrapper
  41. @decorator_function
  42. def print_function(text):
  43. return "Your text is: " + text
  44. # print(print_function("Hello"))
  45. def decorator(func):
  46. def wrapper(a, b):
  47. if a < 0 or b < 0:
  48. print("YES")
  49. result = func(a, b)
  50. return result
  51. return wrapper
  52. # Connect decorator please
  53. @decorator
  54. def main(a, b):
  55. return a + b
  56. # x, y = [int(x) for x in input().split()]
  57. # print(main(3, 6))
  58. # print(main(-3, 6))
  59. def test_exc_1(a, b):
  60. res = 0
  61. try:
  62. print(a/b)
  63. except Exception as e:
  64. print("Error:", Exception)
  65. def test_exc_2(a, b):
  66. res = 0
  67. try:
  68. print(a/b)
  69. except ZeroDivisionError:
  70. print("Error")
  71. except:
  72. print("Something another")
  73. def test_exc_3():
  74. try:
  75. a, b = int(input()), int(input())
  76. print(a +b)
  77. except:
  78. print("error")
  79. finally:
  80. print("end")
  81. def test_exc_4():
  82. try:
  83. a, b = int(input()), int(input())
  84. print(a + b)
  85. except:
  86. print("error")
  87. else:
  88. print("end")
  89. def test_raise():
  90. a, b = int(input()), int(input())
  91. if a + b == 3:
  92. raise RuntimeError("Oops, sum is 3")
  93. else:
  94. print(a + b)