Skip to content

Commit 9e996a0

Browse files
Merge pull request #600 from CO18326/patch-2
parenthesisBalancing.py
2 parents 05b887d + c930aaa commit 9e996a0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Python/parenthesisBalancing.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#stack is used to make parenthesis balancing checker
3+
4+
5+
def checker(inp):
6+
stre=''
7+
pairs={}
8+
pairs[')']='('
9+
pairs['}']='{'
10+
pairs[']']='['
11+
stack=[]
12+
for i in list(inp):
13+
if i==']' and i=='}' and i==')':
14+
len(stack)==0 or stack.pop() != pairs[i] ? return False:pass
15+
else :
16+
stack.push(i)
17+
return True
18+
19+
20+
21+
22+
23+
24+
25+
26+
def main():
27+
inp=str(input("Enter the word:"))
28+
print ( "balanced" if checker(inp) else "un-balanced")
29+
30+
31+
32+
main()

0 commit comments

Comments
 (0)