The problem is that you are using is instead of ==. The is operator performs object identity comparison, which “happens to work” for all numbers below 256 due to implementation details. 251 is the biggest prime below 256 (check here, next prime is 257) and after that the is returns False:
>>> 254 + 1 is 255
True
>>> 255 + 1 is 256
True
>>> 256 + 1 is 257
False
The equality operator is ==:
>>> 254 + 1 == 255
True
>>> 255 + 1 == 256
True
>>> 256 + 1 == 257
True