The is
keyword checks for identity
, not equality.
Change your to ==
in the elif
's and '!=' in the while loop, and this error should not appear.
To see this in action, consider this code:
a = []
b = []
print id(a)
print id(b)
print a is b
print a == b
which outputs
33444128
33415256
False
True