-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparanthesis.py
63 lines (53 loc) · 1.18 KB
/
paranthesis.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Stack():
def __init__(self):
self.a = []
self.top = -1
def push(self, ele):
self.a.append(ele)
self.top += 1
def pop(self):
self.a.pop()
self.top -= 1
def isEmpty(self):
if self.top == -1:
return True
else:
return False
s = Stack()
userIn1 = input('Please provide paranthesis:')
counter = 0
for i in userIn1:
if i == '(':
s.push(1)
counter += 1
elif i == ')':
if s.isEmpty():
counter -= 1
else:
s.pop()
counter -= 1
else:
continue
if counter == 0:
print('There are equal number of paranthesis')
else:
print('There are unequal number of paranthesis')
ns = Stack()
userIn2 = input('Please provide html tags:')
counter = 0
for i in userIn2:
if i == '<':
ns.push(1)
counter += 1
elif i == '>':
if ns.isEmpty():
counter -= 1
else:
ns.pop()
counter -= 1
else:
continue
if counter == 0:
print('There are equal number of html tags')
else:
print('There are unequal number of html tags')