나는 이렇게 학습한다/Algorithm & SQL
0828. Basic Mathematical Operations
daco2020
2022. 8. 28. 22:29
Your task is to create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen operation.
Examples(Operator, value1, value2) --> output ('+', 4, 7) --> 11 ('-', 15, 18) --> -3 ('*', 5, 5) --> 25 ('/', 49, 7) --> 7
Solution:
def as_string(func):
def wrapper(*args):
return func(*(str(i) for i in args))
return wrapper
@as_string
def basic_op(operator, value1, value2):
return eval(value1+operator+value2)