Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them. 

```a``` and ```b``` will both be positive integers, and ```a``` will always be the first number in the operation, and ```b``` always the second.

The four operators are "add", "subtract", "divide", "multiply". 

A few examples: 

``` javascript
ArithmeticFunction.arithmetic(5, 2, "add")      => returns 7
ArithmeticFunction.arithmetic(5, 2, "subtract") => returns 3
ArithmeticFunction.arithmetic(5, 2, "multiply") => returns 10
ArithmeticFunction.arithmetic(5, 2, "divide")   => returns 2
```

Try to do it without using if statements!

Difficulty: EASY
Tags: Fundamentals

Starter code:
def arithmetic(a, b, operator):
	

Solutions:
def arithmetic(a, b, operator):
	return {'add': a + b, 'subtract': a - b, 'multiply': a * b, 'divide': a / b}[operator]


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	elif operator == 'divide':
		return a / (b * 1.0)


from operator import add, mul, sub, truediv

def arithmetic(a, b, operator):
	ops = {'add': add, 'subtract': sub, 'multiply': mul, 'divide': truediv}
	return ops[operator](a, b)


import operator

def arithmetic(a, b, operator_name):
	operators = {'add': operator.add, 'subtract': operator.sub, 'multiply': operator.mul, 'divide': operator.truediv}
	return operators[operator_name](a, b)


def arithmetic(a, b, operator):
	return a + b if operator == 'add' else a - b if operator == 'subtract' else a * b if operator == 'multiply' else a / b


def arithmetic(a, b, operator):
	op = {'add': '+', 'subtract': '-', 'multiply': '*', 'divide': '/'}
	return eval('{} {} {}'.format(a, op[operator], b))


def arithmetic(a, b, op):
	d = {'add': a + b, 'subtract': a - b, 'multiply': a * b, 'divide': a / b}
	return d[op]


def arithmetic(a, b, operator):
	c = operator
	if c == 'add':
		return a + b
	if c == 'subtract':
		return a - b
	if c == 'multiply':
		return a * b
	if c == 'divide':
		return a / b


def arithmetic(a, b, operator):
	ops = {'add': '+', 'subtract': '-', 'multiply': '*', 'divide': '/'}
	return eval(str(a) + ops[operator] + str(b))


def arithmetic(a, b, op):
	if op == 'add':
		return a + b
	elif op == 'subtract':
		return a - b
	elif op == 'divide':
		return a / b
	else:
		return a * b


def arithmetic(a, b, operator):
	return a * b if operator == 'multiply' else a / b if operator == 'divide' else a + b if operator == 'add' else a - b


operators = {'add': int.__add__, 'subtract': int.__sub__, 'multiply': int.__mul__, 'divide': int.__truediv__}

def arithmetic(a, b, op):
	return operators[op](a, b)


from operator import add, sub, mul, truediv as div

def arithmetic(a, b, operator):
	return {'add': add, 'subtract': sub, 'multiply': mul, 'divide': div}[operator](a, b)


def arithmetic(a, b, operator):
	ops = {'add': lambda a, b: a + b, 'subtract': lambda a, b: a - b, 'multiply': lambda a, b: a * b, 'divide': lambda a, b: a / b}
	return ops[operator](a, b)


arithmetic = lambda a, b, o: __import__('operator').__dict__[o[:3].replace('div', 'truediv')](a, b)


def arithmetic(a, b, operator):
	formats = {'add': a + b, 'subtract': a - b, 'divide': a / b, 'multiply': a * b}
	return formats.get(operator)


from operator import *

def arithmetic(a, b, operator):
	if operator == 'add':
		return add(a, b)
	elif operator == 'subtract':
		return sub(a, b)
	elif operator == 'multiply':
		return mul(a, b)
	elif operator == 'divide':
		return truediv(a, b)


def arithmetic(a, b, operator):
	return eval(f"{a}{operator[0].translate(str.maketrans('asmd', '+-*/'))}{b}")


def arithmetic(a: int, b: int, operator: str) -> int:
	return {'add': lambda : a + b, 'subtract': lambda : a - b, 'multiply': lambda : a * b, 'divide': lambda : a / b}.get(operator)()


def arithmetic(a, b, operator):
	return (lambda a, b, operator: operator == 'add' and a + b or (operator == 'subtract' and a - b) or (operator == 'multiply' and a * b) or (operator == 'divide' and a / b))(a, b, operator)


def arithmetic(a, b, operator):
	if operator.lower() == 'multiply':
		return eval(f'{a}*{b}')
	if operator.lower() == 'divide':
		return eval(f'{a}/{b}')
	if operator.lower() == 'add':
		return eval(f'{a}+{b}')
	if operator.lower() == 'subtract':
		return eval(f'{a}-{b}')


def arithmetic(a, b, operator):
	if operator.lower() == 'add':
		return a + b
	elif operator.lower() == 'subtract':
		return a - b
	elif operator.lower() == 'multiply':
		return a * b
	else:
		return a / b


def arithmetic(a, b, operator):
	if operator == 'add':
		number = a + b
		return number
	elif operator == 'subtract':
		number = a - b
		return number
	elif operator == 'multiply':
		number = a * b
		return number
	elif operator == 'divide':
		number = a / b
		return number


arithmetic = lambda a, b, s: eval('a%sb' % '-+*/'[ord(s[2]) // 9 - 10])


from operator import add, sub as subtract, mul as multiply, truediv as divide
arithmetic = lambda a, b, operator: eval(operator)(a, b)


def arithmetic(a, b, operator):
	return getattr(a, '__' + operator[:3] + '__', a.__truediv__)(b)


arithmetic = lambda a, b, o: eval(str(a) + {'add': '+', 'subtract': '-', 'multiply': '*', 'divide': '/'}[o] + str(b))


from operator import add, sub, mul, truediv, floordiv
div = truediv
arithmetic = lambda a, b, s: eval(s[:3])(a, b)


def arithmetic(a, b, operator):
	d = dict()
	d['add'] = '+'
	d['subtract'] = '-'
	d['multiply'] = '*'
	d['divide'] = '/'
	return eval('{0} {1} {2}'.format(a, d[operator], b))


def arithmetic(a, b, operator):
	while operator[0] == 'a':
		return a + b
		break
	while operator[0] == 's':
		return a - b
		break
	while operator[0] == 'm':
		return a * b
		break
	else:
		return a / b


def arithmetic(a, b, operator):
	ops = {'add': lambda x, y: x + y, 'subtract': lambda x, y: x - y, 'multiply': lambda x, y: x * y, 'divide': lambda x, y: float(x) / y}
	return ops[operator](a, b)


def arithmetic(a, b, operator):
	return eval(f'{a}{operator}{b}'.replace('add', '+').replace('subtract', '-').replace('divide', '/').replace('multiply', '*'))


def arithmetic(a, b, operator):
	op = {'add': '+', 'subtract': '-', 'multiply': '*', 'divide': '/'}
	if b == 0 and operator == 'divide':
		return 'Error! Division by zero!'
	return eval(f'{a} {op[operator]} {b}') if operator in op else 'Error! Wrong operator!'


a = {'add': '+', 'subtract': '-', 'multiply': '*', 'divide': '/'}

def arithmetic(b, c, d):
	e = a[str(d)]
	f = str(b) + e + str(c)
	return eval(f)


def arithmetic(a, b, operator):
	try:
		x = {'add': a + b, 'subtract': a - b, 'divide': a / b, 'multiply': a * b}
		return x.get(operator)
	except:
		return None


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	elif operator == 'divide':
		return a / b
	else:
		return 'Unsupport operant'


def arithmetic(a, b, op):
	trans = {'add': '+', 'subtract': '-', 'divide': '/', 'multiply': '*'}
	if type(a) == type(b) == int and op in trans.keys():
		return eval(f'{a}{trans[op]}{b}')


def arithmetic(a, b, operator):
	x = [['a', 's', 'm', 'd'], [a + b, a - b, a * b, a / b]]
	return x[1][x[0].index(operator[0])]


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	elif operator == 'divide':
		return a / b
	else:
		return "I don't know!"


def arithmetic(a, b, o):
	if o == 'add':
		r = a + b
	if o == 'subtract':
		r = a - b
	if o == 'multiply':
		r = a * b
	if o == 'divide':
		r = a / b
	return r


def arithmetic(a, b, operator):
	if operator == 'add':
		operator = '+'
	elif operator == 'subtract':
		operator = '-'
	elif operator == 'multiply':
		operator = '*'
	elif operator == 'divide':
		operator = '/'
	return eval('{}{}{}'.format(a, operator, b))


def arithmetic(a, b, operator):
	result = 0
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	else:
		return a / b


def arithmetic(a, b, operator):
	map = {'add': lambda a, b: a + b, 'subtract': lambda a, b: a - b, 'multiply': lambda a, b: a * b, 'divide': lambda a, b: a / b}
	return map[operator](a, b)


import operator as opr

def arithmetic(a, b, operator):
	operations = {'add': opr.add, 'subtract': opr.sub, 'multiply': opr.mul, 'divide': opr.truediv}
	return operations[operator](a, b)


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	elif operator == 'divide':
		return a / b
	else:
		return 'Please input a proper operator.'


import operator as op
f = {'add': op.add, 'subtract': op.sub, 'multiply': op.mul, 'divide': op.truediv}

def arithmetic(a, b, operator):
	return f[operator](a, b)


def arithmetic(a, b, n):
	if n == 'add':
		return a + b
	elif n == 'subtract':
		return a - b
	elif n == 'multiply':
		return a * b
	else:
		return a / b


def arithmetic(a, b, operator):
	operations = {'add': lambda x: a + b, 'subtract': lambda x: a - b, 'multiply': lambda x: a * b, 'divide': lambda x: a / b}
	return operations[operator](1)


arithmetic = lambda a, b, o: getattr(__import__('operator'), o == 'divide' and 'itruediv' or o[:3])(a, b)


def arithmetic(a, b, operator):
	total = 0
	if operator == 'add':
		total = a + b
	elif operator == 'subtract':
		total = a - b
	elif operator == 'multiply':
		total = a * b
	elif operator == 'divide':
		total = a / b
	else:
		return 'Something Went Wrong'
	return total


import operator as o

def arithmetic(a, b, operator):
	ops = {'add': o.add, 'subtract': o.sub, 'multiply': o.mul, 'divide': o.truediv}
	return ops[operator](a, b)


def arithmetic(a, b, op):
	if op == 'add':
		return a + b
	elif op == 'multiply':
		return a * b
	elif op == 'subtract':
		return a - b
	else:
		return a / b


def arithmetic(a, b, operator):
	map_func = {'add': lambda a, b: a + b, 'subtract': lambda a, b: a - b, 'multiply': lambda a, b: a * b, 'divide': lambda a, b: a / b}
	return map_func[operator](a, b)


def arithmetic(a, b, operator):
	ans = 0
	while operator == 'add':
		ans = a + b
		break
	while operator == 'subtract':
		ans = a - b
		break
	while operator == 'multiply':
		ans = a * b
		break
	while operator == 'divide':
		ans = a / b
		break
	return ans


def arithmetic(a, b, o):
	res = 0
	if o == 'add':
		res = a + b
	elif o == 'subtract':
		res = a - b
	elif o == 'multiply':
		res = a * b
	elif o == 'divide':
		res = a / b
	else:
		res = 'Please specify operator ... '
	return res


def arithmetic(a, b, operator):
	ops = {'add': '__add__', 'subtract': '__sub__', 'multiply': '__mul__', 'divide': '__truediv__'}
	return getattr(a, ops[operator])(b)


def arithmetic(a, b, operator):
	if operator == 'add':
		result = a + b
	elif operator == 'subtract':
		result = a - b
	elif operator == 'divide':
		result = a / b
	elif operator == 'multiply':
		result = a * b
	else:
		print("You didn't enter an operator or you misspelled the operator.")
	return result


def arithmetic(a, b, operator):
	res = {'add': a + b, 'subtract': a - b, 'multiply': a * b, 'divide': a / b}
	return res.get(operator, 'Invalid operator')


from operator import add, sub, mul, truediv as div

def arithmetic(a, b, o):
	return eval(f'{o[:3]}({a},{b})')


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	elif operator == 'subtract':
		return a - b
	elif operator == 'multiply':
		return a * b
	elif operator == 'divide':
		return a / b
	else:
		print('how can I do this better?')


def arithmetic(a, b, operator):
	result = 0
	if operator == 'add':
		result = a + b
	elif operator == 'subtract':
		result = a - b
	elif operator == 'multiply':
		result = a * b
	elif operator == 'divide':
		result = a / b
	else:
		print('No operator found')
	return result


def arithmetic(a, b, op):
	return __import__('operator').__dict__['true' * (op[0] == 'd') + op[:3]](a, b)


def arithmetic(a, b, operator):
	if operator == 'add':
		return a + b
	if operator == 'subtract':
		return a - b
	if operator == 'multiply':
		return a * b
	if operator == 'divide':
		return a / b
	raise "Can't recognize operator"


def arithmetic(a, b, operator):
	c = ['add', 'subtract', 'multiply', 'divide']
	d = [a + b, a - b, a * b, a / b]
	n = 0
	while c[0] != operator:
		c.remove(c[0])
		n += 1
	return d[n]


def arithmetic(a, b, operator):
	if operator == 'add':
		result = a + b
	elif operator == 'subtract':
		result = a - b
	elif operator == 'multiply':
		result = a * b
	elif operator == 'divide':
		result = a / b
	return result
result = arithmetic(5, 2, 'divide')
print(result)