#NEWLINE# def parseEquation( self , input ) : #NEWLINE# #INDENT# 'Solves the equation specified by the input string.\n\n        Args:\n            input (str): An equation, specified in words, containing some\n                combination of numbers, binary, and unary operations.\n\n        Returns:\n            The floating-point result of carrying out the computation.\n        ' #NEWLINE# input = MathService . _preprocess ( input ) #NEWLINE# split = input . split ( ' ' ) #NEWLINE# for ( i , w ) in enumerate ( split ) : #NEWLINE# #INDENT# if ( w in self . __unaryOperators__ ) : #NEWLINE# #INDENT# op = self . __unaryOperators__ [ w ] #NEWLINE# eq1 = ' ' . join ( split [ : i ] ) #NEWLINE# eq2 = ' ' . join ( split [ ( i + 1 ) : ] ) #NEWLINE# result = MathService . _applyUnary ( self . parseEquation ( eq2 ) , op ) #NEWLINE# return self . parseEquation ( ( ( eq1 + ' ' ) + str ( result ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# def extractNumbersAndSymbols( input ) : #NEWLINE# #INDENT# numbers = [ ] #NEWLINE# symbols = [ ] #NEWLINE# next_number = '' #NEWLINE# for w in input . split ( ' ' ) : #NEWLINE# #INDENT# if ( w in self . __binaryOperators__ ) : #NEWLINE# #INDENT# symbols . append ( self . __binaryOperators__ [ w ] ) #NEWLINE# if next_number : #NEWLINE# #INDENT# numbers . append ( next_number ) #NEWLINE# next_number = '' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if next_number : #NEWLINE# #INDENT# next_number += ' ' #NEWLINE# #UNINDENT# next_number += w #NEWLINE# #UNINDENT# #UNINDENT# if next_number : #NEWLINE# #INDENT# numbers . append ( next_number ) #NEWLINE# #UNINDENT# def convert( n ) : #NEWLINE# #INDENT# if ( n in self . __constants__ ) : #NEWLINE# #INDENT# return self . __constants__ [ n ] #NEWLINE# #UNINDENT# converter = NumberService ( ) #NEWLINE# return converter . parse ( n ) #NEWLINE# #UNINDENT# numbers = [ convert ( n ) for n in numbers ] #NEWLINE# return ( numbers , symbols ) #NEWLINE# #UNINDENT# ( numbers , symbols ) = extractNumbersAndSymbols ( extractNumbersAndSymbols ) #NEWLINE# return MathService . _calculate ( numbers , symbols )