open input txt open output txt while True and readline strip if not br

 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
a=open("input.txt","r")
b=open('output.txt','w')
S=[]
t = 0
while True and t==0:
s=a.readline().strip()
if not s:
break
if s[0]=='+':
S.append(int(s[1:]))
if s[0]=='-':
if len(S)==0:
b.write('ERROR')
t = 1
else:
S.pop()
if t == 0:
if len(S)==0:
b.write('EMPTY')
else:
for i in range (len(S)):
b.write(str(S[i]))
b.write(' ')
a.close()
b.close()