erly at the end of the stringwhen all symbols have been processedthe stack should be empty import stack #import the stack class as previously defined def par_checker(symbol_string) stack(balanced true index while index len(symbol_stringand balancedsymbol symbol_string[indexif symbol ="(" push(symbolelseif is_empty()balanced false elses pop( index index if balanced and is_empty()return true elsereturn false print(par_checker('((()))')print(par_checker('(()')this functionpar_checkerassumes that stack class is available and returns boolean result as to whether the string of parentheses is balanced note that the boolean variable balanced is initialized to true as there is no reason to assume otherwise at the start if the current symbol is (then it is pushed on the stack (lines - note also in line that pop simply removes symbol from the stack the returned value is not used since we know it must be an opening symbol seen earlier at the end (lines - )as long as the expression is balanced and the stack has been completely cleaned offthe string represents correctly balanced sequence of parentheses balanced symbols ( general casehe balanced parentheses problem shown above is specific case of more general situation that arises in many programming languages the general problem of balancing and nesting different kinds of opening and closing symbols occurs frequently for examplein python square bracketsand ]are used for listscurly bracesand }are used for dictionariesand parenthesesand )are used for tuples and arithmetic expressions it is possible to mix symbols as long as each maintains its own open and close relationship strings of symbols such as the stack abstract data type