Question: PYTHON CODE PLEASE FOLLOW THE QUESTION'S REQUIREMENTS !!!!!!! NO PRINT FUNCTION CAN BE USED, ONLY CAN USE RETURN Task 3: Balanced brackets Write a function,

PYTHON CODE

PLEASE FOLLOW THE QUESTION'S REQUIREMENTS !!!!!!!

NO PRINT FUNCTION CAN BE USED, ONLY CAN USE RETURN

Task 3: Balanced brackets

Write a function, balanced brackets(string) that takes in a string made up of brackets, e.g (, [, {, ), ] and }. The function should return a Boolean representing whether or not the string is balanced in regards to brackets. A string said to be balanced if it had many opening brackets of a given type as it has closing brackets of that type and if no bracket is unmatched. Note that closing bracket cannot overlap each other as in [(]).

Input: a non-empty list of strings brackets that represents the brackets stack you are checking.

Output: a Boolean, True if the brackets are balanced; otherwise False.

Examples

a) Calling balanced brackets(([])()(())(){}) will return True.

b) Calling balanced brackets(()[] { } {) will return False.

c) Calling balanced brackets(()([])) will return True.

d) Calling balanced brackets(()()[{()})]) will return False.

e) Calling balanced brackets((([]()()){})) will return True.

Marks are given for the correct behavior of the different functions: (a) 1 mark for correct loop condition. 2 marks for correct answers.

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!