1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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
|