title: Python checking the parentheses are equal on both sides
body: <p>I wrote a code but dont know how to make it find the extra unbalanced parentheses this is my code</p>
  <pre><code>def checkBalance(str1):
  count = 0
  for i in str1:
      if i == &quot;(&quot; or i == &quot;{&quot; or i == &quot;[&quot;:
          count += 1
      elif i == &quot;)&quot; or i == &quot;}&quot; or i == &quot;]&quot;:
          count -= 1
      if count &lt; 0:
          return False and str1.find(&quot;)&quot;)
  return count == 0 
  
  str1 = input(&quot;Enter a string of brackets: &quot;)
  print(&quot;Given string is balanced :&quot;, checkBalance(str1))
  </code></pre>
  <p>For example if i input ()()() the code will say it is balanced but if i input something like this (())) it will say it is not balanced. what i want to add is that it would say code is balanced or not and says the first position of the side that is not balanced like <em><strong>CODE IS NOT BALANCED &quot;)&quot; POSTITION 3</strong></em> and i would like to do it for the other side aswell if it is not balanced ((()) <em><strong>CODE IS NOT BALANCED &quot;(&quot; POSTITION 1</strong></em></p>