import math
ops = {
    '+': float.__add__,
    '-': float.__sub__,
    '*': float.__mul__,
    'x': float.__mul__,
    '/': float.__truediv__,
    '//': float.__floordiv__,
    '%': float.__mod__,
    '^': pow,
    '!': math.factorial
    }
unary_ops = ('!',)
arg_count = {ops[op]: 1 if op in unary_ops else 2 for op in ops}

def evaluate(expr):
    stack = []
    for token in expr.split():
        if token in ops:
            op = ops[token]
            args = reversed([stack.pop() for _ in range(arg_count[op])])
            stack.append(float(op(*args)))
        else:
            stack.append(float(token))
    result = stack[0]
    return int(result) if result.is_integer else result

print(evaluate('0.5 1 2 ! * 2 1 ^ + 10 + *'))
print(evaluate('1 2 3 4 ! + - / 100 *'))
print(evaluate('100 807 3 331 * + 2 2 1 + 2 + * 5 ^ * 23 10 558 * 10 * + + *'))