Below is my code:
def interpret(value, commands, args):
ans = 0
valid = ['+','-','*']
if set(commands).issubset(valid):
for ope,arg in zip(commands,args):
ans = eval(r'value ope arg')
value = ans
return print (ans)
else :
return print('-1')
def main():
interpret(1, ['+'], [1])
if __name__ == '__main__':
main()
Have tried eval(value+ope+arg
) but got error
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Have also looked for other solutions like to use regular expression and then evaluating it but not able to evaluate the expression
Expected answer = 2