while s [p ] == ‘!’:
UnboundLocalError: local variable ‘p’ referenced before assignment
я уже с ней встречался и не случайно задал не просто целое число p, а список из одного элемнта. в чём же проблема?
s = raw_input ()
p = [0]
def reverse (x):
if x == 0:
return 1
else:
return 0
def value ():
r = 0
while s [p [0]] == '!': # ОШИБКА ТУТ
r = reverse (r)
p [0] += 1
if s [p [0]] in ['1', '0']:
if r:
res = reverse (int (s [p [0]]))
else:
res = int (s [p [0]])
else:
p [0] += 1
if r:
res = reverse (value ())
else:
res = value ()
p [0] += 1
while p [0] < len (s) and s [p [0]] in ['|', '^', '&']:
sig = s [p [0]]
p [0] += 1
r = 0
while s [p [0]] == '!':
r = reverse (r)
p [0] += 1
if s [p [0]] in ['1', '0']:
if r:
temp = reverse (int (s [p [0]]))
else:
temp = int (s [p [0]])
else:
p [0] += 1
if r:
temp = reverse (value ())
else:
temp = value ()
if sig == '&':
res *= temp
if sig == '|':
res += temp
if sig == '^':
res = ((res + temp) == res) or ((res + temp) == temp)
p [0] += 1
p += 1
return res
print value ()