-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8.2.2.py
More file actions
56 lines (41 loc) · 1.32 KB
/
Copy path8.2.2.py
File metadata and controls
56 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Напишіть Python-функцію під назвою operation_mapper,
яка приймає на вхід математичну операцію у вигляді рядка: “+”, “-”, “/”, “*”, “**”
(в іншому випадку, має викликатися правильний виняток ValueError);
має повертатися функція, яка працює з двома вхідними параметрами,
застосовує математичну операцію до них і повертає результат.
4 week .3 task
def operation_mapper(operation):
# write your program here
eval(operator.join(map(str,number)))
"""
a,b = 0,0
operation = ''
def _sub(a, b):
return a-b
def _add(a, b):
return a+b
def _mul(a, b):
return a*b
def _div(a, b):
return a/b
def _squ(a, b):
return a**b
##others____
def non_operation(*args, **kwargs):
return f"ValueError"
raise
def operation_mapper(operation):
operation_dict = {
"-": _sub,
"+": _add,
"*": _mul,
"/": _div,
"**": _squ,
}
if operation in operation_dict:
return operation_dict[operation]
else:
return non_operation
print(operation_mapper('+')(2, 3))