def isbalanced(s):
          c= 0
          ans=False
          for i in s:
              if i == “(“:
                  c += 1
              elif i == “)”:
                  c-= 1
              if c < 0:
                  return ans
          if c==0:
              return not ans
          return ans
      s=input(“Enter a string of brackets: “) 
      print(“Given string is balanced :”,isbalanced(s))
      
      Python language logo

      Program to check the balance of parenthesis

      0

      0

      avatar
      drzyadav

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.