Check if the number is balanced | Function to check whether N is Balanced Number or not ; Calculating the Leftsum and rightSum simultaneously ; Typecasting each character to integer and adding the digit to respective sums ; Driver Code ; Function call
def BalancedNumber ( s ) : NEW_LINE INDENT Leftsum = 0 NEW_LINE Rightsum = 0 NEW_LINE for i in range ( 0 , int ( len ( s ) / 2 ) ) : NEW_LINE INDENT Leftsum = Leftsum + int ( s [ i ] ) NEW_LINE Rightsum = ( Rightsum + int ( s [ len ( s ) - 1 - i ] ) ) NEW_LINE DEDENT if ( Leftsum == Rightsum ) : NEW_LINE INDENT print ( " Balanced " , end =   ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Balanced " , end =   ' ' ) NEW_LINE DEDENT DEDENT s = "12321" NEW_LINE BalancedNumber ( s ) NEW_LINE