| 146 | |
| 147 | print("Example 5") |
| 148 | class Timer: |
| 149 | def __init__(self, period): |
| 150 | self.current = period |
| 151 | self.period = period |
| 152 | |
| 153 | def reset(self): |
| 154 | print("Resetting") |
| 155 | self.current = self.period |
| 156 | |
| 157 | def tick(self): |
| 158 | before = self.current |
| 159 | self.current -= 1 |
| 160 | return before |
| 161 | |
| 162 | def __bool__(self): |
| 163 | return self.current > 0 |
| 164 | |
| 165 | |
| 166 | print("Example 6") |