#import readline
#from prettytable import PrettyTable

def add(a,b):
    return a + b
def subtract(a,b):
    return a - b
def multiply(a,b):
    return a*b
def divide(a,b):
    return b/a;
def exponent(a,b):
    return b ** a

#table = PrettyTable(["Equation","Result"])
class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

ops = {"+": add, "-": subtract,"*": multiply,"/":divide,"^":exponent}

def calculate(string):
    stack=list()
    if (len(string.split()) < 3) & (string != "end"):
        print(bcolors.WARNING + "Not valid expression" + bcolors.HEADER)
    for token in string.split():
        if token not in ops.keys():
            if token == "end":
                #print(table)
                exit()
            stack.append(int(token))
        else:
            if len(stack)<2:
                print(bcolors.WARNING + "Not valid expression" + bcolors.HEADER)
                return
            arg2 = stack.pop()
            arg1 = stack.pop()
            function = ops[token]
            result = function(arg2,arg1)
            #table.add_row([str(arg2) +" "+ str(arg1) +" "+ token,str(result)])
            #print(bcolors.OKGREEN + str(arg2) +" "+ str(arg1) +" "+ bcolors.OKBLUE + token +" "+ bcolors.OKGREEN+str(result) + bcolors.HEADER)
            stack.append(result)

    return stack.pop()

def main():
    print(bcolors.HEADER + "Staring RPN")
    while True:
        calculate(input("rpn calc "))


if __name__ == "__main__":
    main()

c229190644596e0851a1e8e0b1c427065efcc152
def add(a, b):
    return a + b


<mask token>


def multiply(a, b):
    return a * b


<mask token>


def exponent(a, b):
    return b ** a


class bcolors:
    HEADER = '\x1b[95m'
    OKBLUE = '\x1b[94m'
    OKGREEN = '\x1b[92m'
    WARNING = '\x1b[93m'
    FAIL = '\x1b[91m'
    ENDC = '\x1b[0m'
    BOLD = '\x1b[1m'
    UNDERLINE = '\x1b[4m'


<mask token>

def add(a, b):
    return a + b


def subtract(a, b):
    return a - b


def multiply(a, b):
    return a * b


<mask token>


def exponent(a, b):
    return b ** a


class bcolors:
    HEADER = '\x1b[95m'
    OKBLUE = '\x1b[94m'
    OKGREEN = '\x1b[92m'
    WARNING = '\x1b[93m'
    FAIL = '\x1b[91m'
    ENDC = '\x1b[0m'
    BOLD = '\x1b[1m'
    UNDERLINE = '\x1b[4m'


<mask token>

def add(a, b):
    return a + b


def subtract(a, b):
    return a - b


def multiply(a, b):
    return a * b


<mask token>


def exponent(a, b):
    return b ** a


class bcolors:
    HEADER = '\x1b[95m'
    OKBLUE = '\x1b[94m'
    OKGREEN = '\x1b[92m'
    WARNING = '\x1b[93m'
    FAIL = '\x1b[91m'
    ENDC = '\x1b[0m'
    BOLD = '\x1b[1m'
    UNDERLINE = '\x1b[4m'


<mask token>


def calculate(string):
    stack = list()
    if (len(string.split()) < 3) & (string != 'end'):
        print(bcolors.WARNING + 'Not valid expression' + bcolors.HEADER)
    for token in string.split():
        if token not in ops.keys():
            if token == 'end':
                exit()
            stack.append(int(token))
        else:
            if len(stack) < 2:
                print(bcolors.WARNING + 'Not valid expression' + bcolors.HEADER
                    )
                return
            arg2 = stack.pop()
            arg1 = stack.pop()
            function = ops[token]
            result = function(arg2, arg1)
            stack.append(result)
    return stack.pop()


<mask token>

def add(a, b):
    return a + b


def subtract(a, b):
    return a - b


def multiply(a, b):
    return a * b


<mask token>


def exponent(a, b):
    return b ** a


class bcolors:
    HEADER = '\x1b[95m'
    OKBLUE = '\x1b[94m'
    OKGREEN = '\x1b[92m'
    WARNING = '\x1b[93m'
    FAIL = '\x1b[91m'
    ENDC = '\x1b[0m'
    BOLD = '\x1b[1m'
    UNDERLINE = '\x1b[4m'


<mask token>


def calculate(string):
    stack = list()
    if (len(string.split()) < 3) & (string != 'end'):
        print(bcolors.WARNING + 'Not valid expression' + bcolors.HEADER)
    for token in string.split():
        if token not in ops.keys():
            if token == 'end':
                exit()
            stack.append(int(token))
        else:
            if len(stack) < 2:
                print(bcolors.WARNING + 'Not valid expression' + bcolors.HEADER
                    )
                return
            arg2 = stack.pop()
            arg1 = stack.pop()
            function = ops[token]
            result = function(arg2, arg1)
            stack.append(result)
    return stack.pop()


def main():
    print(bcolors.HEADER + 'Staring RPN')
    while True:
        calculate(input('rpn calc '))


<mask token>

#import readline
#from prettytable import PrettyTable

def add(a,b):
    return a + b
def subtract(a,b):
    return a - b
def multiply(a,b):
    return a*b
def divide(a,b):
    return b/a;
def exponent(a,b):
    return b ** a

#table = PrettyTable(["Equation","Result"])
class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

ops = {"+": add, "-": subtract,"*": multiply,"/":divide,"^":exponent}

def calculate(string):
    stack=list()
    if (len(string.split()) < 3) & (string != "end"):
        print(bcolors.WARNING + "Not valid expression" + bcolors.HEADER)
    for token in string.split():
        if token not in ops.keys():
            if token == "end":
                #print(table)
                exit()
            stack.append(int(token))
        else:
            if len(stack)<2:
                print(bcolors.WARNING + "Not valid expression" + bcolors.HEADER)
                return
            arg2 = stack.pop()
            arg1 = stack.pop()
            function = ops[token]
            result = function(arg2,arg1)
            #table.add_row([str(arg2) +" "+ str(arg1) +" "+ token,str(result)])
            #print(bcolors.OKGREEN + str(arg2) +" "+ str(arg1) +" "+ bcolors.OKBLUE + token +" "+ bcolors.OKGREEN+str(result) + bcolors.HEADER)
            stack.append(result)

    return stack.pop()

def main():
    print(bcolors.HEADER + "Staring RPN")
    while True:
        calculate(input("rpn calc "))


if __name__ == "__main__":
    main()
