**Debug** a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "\*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified characters, the function should return null.

```
calculate(2,"+", 4); //Should return 6
calculate(6,"-", 1.5); //Should return 4.5
calculate(-4,"*", 8); //Should return -32
calculate(49,"/", -7); //Should return -7
calculate(8,"m", 2); //Should return null
calculate(4,"/",0) //should return null
```

Kind of a fork (not steal :)) of [Basic Calculator][1] kata by [TheDoctor][2]. 

[1]: http://www.codewars.com/kata/basic-calculator/javascript
[2]: http://www.codewars.com/users/528c45adbd9daa384300068d

Difficulty: introductory

Starter code:

def calculate(a, o, b):
	

Solutions:
from operator import add, sub, mul, truediv
D = {'+':add, '-':sub, '*':mul, '/':truediv}

def calculate(a, o, b):
    try: return D[o](a, b)
    except: pass

def calculate(a, o, b):
    result = 0
    if(o == "+"):
        return a + b
    elif(o == "-"):
        return a - b
    elif(o == "/" and b == 0):
        return None
    elif(o == "/"):
        return a / b
    elif(o == "*" and b == 0):
        return b
    elif(o == "*"):
        return a * b
    else:
        return None
    return result


def calculate(a, o, b):
    if a==b==0 and o=='**':return
    try:    return eval(f'{a}{o}{b}')
    except: return

calculate = lambda a,o,b, m=__import__("operator"): None if o not in "+-*/" or o=='/' and not b else {"+":m.__add__, "-":m.__sub__, "*":m.__mul__, "/":m.__truediv__}[o](a, b)

def calculate(a, o, b):
    if o == "+":
        return a + b
    if o == "-":
        return a - b
    if o == "*":
        return a * b
    if o == "/" and b != 0:
        return a / b


# one-liner
#    return [a+b, a-b, a*b, a/b if b else None, None]["+-*/".find(o)]


def calculate(a, o, b):
    if (o == "+"):
        return a + b
    elif (o == "-"):
        return a - b
    elif b != 0 and o == "/":
        return a / b
    elif (o == "*"):
        return a * b
    return None

calculate=lambda a,o,b:eval(str(a)+o+str(b)) if o in '+-/*' and o+str(b)!='/0' else None