generate functionFri, 10 Mar 2023

An arithmetic expression is written as a string, for example: "10 + 25 - 12" or "10 + 25 - 12 + 20 - 1 + 3", etc. That is, the number of actions can be different. It is necessary to perform the calculation and display the result on the screen. It is assumed that only addition (+) and subtraction (-) are used here as arithmetic operations, and non-negative integers are used as operands. Note that these operators can be written with or without spaces.

def arithmeticExpression(expression): return eval(expression) arithmeticExpression("1+2")

Questions about programming?Chat with your personal AI assistant