t | class Pushpull: | t | class Pushpull: |
| | | |
| def __init__(self, n=0): | | def __init__(self, n=0): |
| Pushpull.pos = n | | Pushpull.pos = n |
| | | |
| def push(self, n=1): | | def push(self, n=1): |
| Pushpull.pos += n | | Pushpull.pos += n |
| | | |
| def pull(self, n=1): | | def pull(self, n=1): |
| Pushpull.pos -= n | | Pushpull.pos -= n |
| | | |
| def __iter__(self): | | def __iter__(self): |
| if Pushpull.pos < 0: | | if Pushpull.pos < 0: |
| return iter(range(0, Pushpull.pos, -1)) | | return iter(range(0, Pushpull.pos, -1)) |
| else: | | else: |
| return iter(range(Pushpull.pos)) | | return iter(range(Pushpull.pos)) |
| | | |
| def __str__(self): | | def __str__(self): |
| if Pushpull.pos < 0: | | if Pushpull.pos < 0: |
| return f'<{abs(Pushpull.pos)}<' | | return f'<{abs(Pushpull.pos)}<' |
| elif Pushpull.pos > 0: | | elif Pushpull.pos > 0: |
| return f'>{Pushpull.pos}>' | | return f'>{Pushpull.pos}>' |
| else: | | else: |
| return '<0>' | | return '<0>' |