Write a program called paren_checker.py
that imports the atds
module, and has a single boolean function isValid(expr)
that identifies whether a string of parentheses is legal or not. It will do this by creating a Stack
object from the atds
module and using it to track parentheses in the expression.
Legal parenthetical expressions include:
( a )
(a) (b) (c)
((( abc )))
( a (b) c (( d )) e )
((()()()))
Illegal expressions include:
) a
) b (
( a ) )
( ( ) ( ) ( ( )
Once you've got paren_checker.py
working, create a new version of the program called bracket_checker.py
which checks expressions that include parentheses, square brackets and curly braces as well. To be legal, brackets must be nested appropriately.
Legal expressions include:
( [ ] )
( [ { } ] )
( [ ] { } )
([{ }])
Illegal expressions include:
( [ ) ]
( { ] )
{ [ ( ] } )
[