Question: # Constants BALANCED = 0 MORE_LEFT = 1 MORE_RIGHT = 2 MISMATCHED = 3 def has_balanced_brackets(string): ------------------------------------------------------- Determines if a string contains balanced brackets

 # Constants BALANCED = 0 MORE_LEFT = 1 MORE_RIGHT = 2

# Constants BALANCED = 0 MORE_LEFT = 1 MORE_RIGHT = 2 MISMATCHED = 3 def has_balanced_brackets(string): """ ------------------------------------------------------- Determines if a string contains balanced brackets or not. Non-bracket characters are ignored. Uses a stack. Brackets include {}, [], (), . Use: balanced = has_balanced_brackets(string) ------------------------------------------------------- Parameters: string - the string to test (str) Returns: balanced (int) - BALANCED if the brackets in string are balanced MISMATCHED if the brackets in string are mismatched MORE_RIGHT if there are more right brackets than left in string MORE_LEFT if there are more left brackets than right in string ------------------------------------------------------- """

The function must use one and only one stack to solve the problem. Show enough tests to cover a balanced string and the three types of unbalanced strings. An empty string has balanced brackets; a string that contains no brackets has balanced brackets.

5. Write and test the following function that uses a Stack: Detez.ine2 : 2tzini conta-L2 22dbzacket2 c not. Hor-21 ackat dd the function to a lyDev module named tons,zr. Test it trom a PyDev module named t5. See: Stacks - Balancedl Brackets The unction tnust use one nd on one sia( Io so ve lhe poblern. Show enouah tesl s lo (over d balante( string ard the three l pes o unbrl dned strini s n emipty string has brllan ed brdt cels; a strint that contains no brackets has balanced brackets Your testing program should convert these constants into a readable message for the user (the furnction itself must not do anyp!) if balanced-EiliNCED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!