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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started