#NEWLINE# def calculate( self , s ) : #NEWLINE# #INDENT# ( operands , operators ) = ( [ ] , [ ] ) #NEWLINE# operand = '' #NEWLINE# for i in reversed ( xrange ( len ( s ) ) ) : #NEWLINE# #INDENT# if s [ i ] . isdigit ( ) : #NEWLINE# #INDENT# operand += s [ i ] #NEWLINE# if ( ( i == 0 ) or ( not s [ ( i - 1 ) ] . isdigit ( ) ) ) : #NEWLINE# #INDENT# operands . append ( int ( operand [ : : ( - 1 ) ] ) ) #NEWLINE# operand = '' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( s [ operands ] == ')' ) or ( s [ i ] == '*' ) or ( s [ i ] == '/' ) ) : #NEWLINE# #INDENT# operators . append ( s [ i ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( s [ i ] == '+' ) or ( s [ i ] == '-' ) ) : #NEWLINE# #INDENT# while ( operators and ( ( operators [ ( - 1 ) ] == '*' ) or ( operators [ ( - 1 ) ] == '/' ) ) ) : #NEWLINE# #INDENT# self . compute ( operands , operators ) #NEWLINE# #UNINDENT# operators . append ( s [ i ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( s [ i ] == '(' ) : #NEWLINE# #INDENT# while ( operators [ ( - 1 ) ] != ')' ) : #NEWLINE# #INDENT# self . compute ( operands , operators ) #NEWLINE# #UNINDENT# operators . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# while operators : #NEWLINE# #INDENT# self . compute ( operands , operators ) #NEWLINE# #UNINDENT# return operands [ ( - 1 ) ]