Hi again,
I am working on more homework. I have ideas of how to solve the problem but I am running into a bug I don't understand
Traceback (most recent call last):
File "/Users/leon/PycharmProjects/playpen/test5.py", line 19, in <module>
print (not_bad("this is a test"))
File "/Users/leon/PycharmProjects/playpen/test5.py", line 8, in not_bad
if a < b:
UnboundLocalError: local variable 'a' referenced before assignment
I feel like a got assigned in the if statement.
Thanks as always.
I am working on more homework. I have ideas of how to solve the problem but I am running into a bug I don't understand
def not_bad(s): t = s.split() for x in t: if x == "not": a = t.index(x) if x == "bad": b = t.index(x) if a < b: newlist = [range (a, b)] del t[newlist] print (t) return t print (not_bad("this is a test"))Basically just trying to determine if one word shows up before another in a sentence but when I run that test it gives me back:
Traceback (most recent call last):
File "/Users/leon/PycharmProjects/playpen/test5.py", line 19, in <module>
print (not_bad("this is a test"))
File "/Users/leon/PycharmProjects/playpen/test5.py", line 8, in not_bad
if a < b:
UnboundLocalError: local variable 'a' referenced before assignment
I feel like a got assigned in the if statement.
Thanks as always.