-
Notifications
You must be signed in to change notification settings - Fork 138
/
Numtoword.py
44 lines (44 loc) · 864 Bytes
/
Numtoword.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#it can check if your all braces is balanced or not like {[()]} is balanced
#and [{]} is not balanced
p=input("Input Your paragraph :")
symbollist=["{","}","[","]","(",")"]
opensymbol=["[","{","("]
closesymbol=["]","}",")"]
templist=[]
for word in p:
for char in word:
if char in symbollist:
templist.append(char)
def check():
global templist
tlen=len(templist)
if tlen==0:
return 0
elif(tlen==1):
return
for i in range(len(templist)):
#item
try:
I=templist[i]
except:
break
if I in opensymbol:
continue
#previousitem
pI=templist[i-1]
if I in closesymbol and i==0:
break
if I in closesymbol:
op=closesymbol.index(I)
#oppositeitem
opI=opensymbol[op]
if pI==opI:
templist.pop(i)
templist.pop(i-1)
else:
print("not Balanced")
return
check()
check()
if len(templist)==0:
print("balanced")