|
@@ -0,0 +1,41 @@
|
|
|
+from typing import Callable
|
|
|
+
|
|
|
+
|
|
|
+def calculate(x:float, y:float, operation:str='a') -> None:
|
|
|
+ def add():
|
|
|
+ print(x + y)
|
|
|
+ def sub():
|
|
|
+ print(x - y)
|
|
|
+ def div():
|
|
|
+ if y == 0:
|
|
|
+ print("На ноль делить нельзя!")
|
|
|
+ else:
|
|
|
+ print(x/y)
|
|
|
+ def mul():
|
|
|
+ print(x*y)
|
|
|
+
|
|
|
+ match operation:
|
|
|
+ case "a":
|
|
|
+ add()
|
|
|
+ case "s":
|
|
|
+ sub()
|
|
|
+ case "d":
|
|
|
+ div()
|
|
|
+ case "m":
|
|
|
+ mul()
|
|
|
+ case _:
|
|
|
+ print("Ошибка. Данной операции не существует")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def get_math_func(operation: str) -> Callable[[int, int], int]:
|
|
|
+ def add(a: int, b: int) -> int:
|
|
|
+ return a + b
|
|
|
+
|
|
|
+ def subtract(a: int, b: int) -> int:
|
|
|
+ return a - b
|
|
|
+
|
|
|
+ if operation == "+":
|
|
|
+ return add
|
|
|
+ elif operation == "-":
|
|
|
+ return subtract
|