def e( x, y, s ) : ''' Return the value of the expression x s y, where x and y are operands, and s is an arithmetic operator. ''' # Example is x = 19.5, y = 5.25, and s1 can be +-*/ (multiplication is * and division is /) # We want to return the result of this operation x s y where x and y are numbers and s is the operator (+-*/) # A single = is assignment (ex. x = 2) and == is a logical operator that checks if two things are equal (evaluates # to True/False) # ex. 5 == 5 is True # ex. 2 == 5 is False # Conditionally check if s is a certain operator and evaluate the result based on if s == the operator if ( s == '+' ): # Addition result = x + y elif ( s == '-' ): # Subtraction result = x - y elif ( s == '*' ): # Multiplication result = x * y elif ( s == '/' ): # Division result = x / y else: # They gave us a bad operator like @ result = None return result ''' DO NOT MODIFY THE BELOW CODE ''' if ( __name__ == '__main__' ) : import calc x1 = 19.5; y1 = 5.25; s1 = '+' x2 = 12.5; y2 = 6.5; s2 = '-' x3 = 12.5; y3 = 4.5; s3 = '*' x4 = 10.0; y4 = 2.25; s4 = '/' x5 = 1.0; y5 = 5.0; s5 = '@' r1 = calc.e( x1, y1, s1 ); print( x1, s1, y1, '=', r1 ) r2 = calc.e( x2, y2, s2 ); print( x2, s2, y2, '=', r2 ) r3 = calc.e( x3, y3, s3 ); print( x3, s3, y3, '=', r3 ) r4 = calc.e( x4, y4, s4 ); print( x4, s4, y4, '=', r4 ) r5 = calc.e( x5, y5, s5 ); print( x5, s5, y5, '=', r5 )