Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def htmlCheck(strn):
  2.     opentagStack=Stack()
  3.     balance=True
  4.    
  5.     while balance == True:
  6.         opener=strn.find('<')
  7.         closer=strn.find('>')
  8.         testcase=opener+1
  9.         if testcase >= len(strn):
  10.             print("Is not balanced")
  11.             balance=False
  12.         else:
  13.             result=(strn[testcase])
  14.             if result == '/':
  15.                 if opentagStack.isEmpty() == True:
  16.                     balance= False
  17.                     print('Is Not Balanced')
  18.    
  19.                 else:
  20.                     topvalue=opentagStack.pop()
  21.                     if topvalue != strn[opener+2:closer]:
  22.                         print("Is Not Balanced")
  23.                         balance = False
  24.                
  25.             else:
  26.                 opentagStack.push(strn[opener+1:closer])
  27.             if opentagStack.isEmpty() == True and balance == True:
  28.                 print("This is Balanced")
  29.                 balance=False
  30.         strn=strn[closer+1:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement