数字时钟
| 2 | |
| 3 | |
| 4 | class Clock(object): |
| 5 | """数字时钟""" |
| 6 | |
| 7 | def __init__(self, hour=0, minute=0, second=0): |
| 8 | self._hour = hour |
| 9 | self._minute = minute |
| 10 | self._second = second |
| 11 | |
| 12 | @classmethod |
| 13 | def now(cls): |
| 14 | ctime = localtime(time()) |
| 15 | return cls(ctime.tm_hour, ctime.tm_min, ctime.tm_sec) |
| 16 | |
| 17 | def run(self): |
| 18 | """走字""" |
| 19 | self._second += 1 |
| 20 | if self._second == 60: |
| 21 | self._second = 0 |
| 22 | self._minute += 1 |
| 23 | if self._minute == 60: |
| 24 | self._minute = 0 |
| 25 | self._hour += 1 |
| 26 | if self._hour == 24: |
| 27 | self._hour = 0 |
| 28 | |
| 29 | def show(self): |
| 30 | """显示时间""" |
| 31 | return '%02d:%02d:%02d' % \ |
| 32 | (self._hour, self._minute, self._second) |
| 33 | |
| 34 | |
| 35 | def main(): |
nothing calls this directly
no outgoing calls
no test coverage detected