Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HOW TO PASS THE TEST CASES WITH THE QUESTION import unittest def balance_brackets(string): Write a function balance_brackets(string), which checks if the given

HOW TO PASS THE TEST CASES WITH THE QUESTION 

 

import unittest

def balance_brackets(string):
   """
Write a function balance_brackets(string), which checks if the
given string has balance brackets.  
   For example, balance_brackets('(a)+(b)') returns 'True'.  
   .  

   Note that your program has to work for any input string.
   """
   pass

# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
    self.assertEqual(balance_brackets('()()'), True)
def test2(self):
    self.assertEqual(balance_brackets('))(('), False)
def test3(self):
    self.assertEqual(balance_brackets('(a+b)+c'), True)
def test4(self):
    self.assertEqual(balance_brackets('(a+b)+c)'), False)
def test5(self):
    self.assertEqual(balance_brackets(''), True)
   
if __name__ == '__main__':
unittest.main(exit=True)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

Evaluate the answers accurate to the cent.

Answered: 1 week ago

Question

Evaluate the answers accurate to the cent.

Answered: 1 week ago

Question

Evaluate the answers accurate to the cent. [(20 + 8 5) - 7 (-3)] 9

Answered: 1 week ago