Matching brackets

Report a typo

As you have probably noticed, most code editors check if you used the right number of brackets in your code.

Write a simple brackets checker that, given a string, prints OK if all the brackets are used correctly, and ERROR, otherwise.

Don't forget to check that the brackets are in the correct order (an opening and then a closing one).

A little hint: each time you encounter an opening bracket (, put it on the stack. Do the opposite when you encounter a closing bracket.

Sample Input 1:

(a + b)*c

Sample Output 1:

OK

Sample Input 2:

((a + b)*c

Sample Output 2:

ERROR

Sample Input 3:

)5*).((

Sample Output 3:

ERROR
Write a program in Python 3
expression = input()
___

Create a free account to access the full topic