Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def htmlCheck(strn):
- opentagStack=Stack()
- balance=True
- while balance == True:
- opener=strn.find('<')
- closer=strn.find('>')
- testcase=opener+1
- if testcase >= len(strn):
- print("Is not balanced")
- balance=False
- else:
- result=(strn[testcase])
- if result == '/':
- if opentagStack.isEmpty() == True:
- balance= False
- print('Is Not Balanced')
- else:
- topvalue=opentagStack.pop()
- if topvalue != strn[opener+2:closer]:
- print("Is Not Balanced")
- balance = False
- else:
- opentagStack.push(strn[opener+1:closer])
- if opentagStack.isEmpty() == True and balance == True:
- print("This is Balanced")
- balance=False
- strn=strn[closer+1:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement