def main():
    counter = 0
while counter < 256:
    print(counter)
counter = byte(counter + 1)

def correct(value, bits, signed):
    base = 1 << bits
value %= base
return value - base if signed and value.bit_length() == bits else value
byte, sbyte, word, sword, dword, sdword, qword, sqword = lambda v: correct(v,
    8, False), lambda v: correct(v, 8, True), lambda v: correct(v, 16, False
    ), lambda v: correct(v, 16, True), lambda v: correct(v, 32, False
    ), lambda v: correct(v, 32, True), lambda v: correct(v, 64, False
    ), lambda v: correct(v, 64, True)
if __name__ == '__main__':
    main()
Моделирование целочисленного переполнения в Python