MCPcopy Create free account
hub / github.com/ZiniuLu/Python-100-Days / Clock

Class Clock

Day01-15/Day09/clock.py:4–32  ·  view source on GitHub ↗

数字时钟

Source from the content-addressed store, hash-verified

2
3
4class 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
35def main():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected