python类练习——反方向的钟
谁还不是个杰迷呢【doge】
import time
from time import sleep
class Clock(object):
"""反方向的钟"""
def __init__(self, hour=0, minute=0, second=0):
self._hour = hour
self._minute = minute
self._second = second
def run(self):
"""走字"""
self._second -= 1
if self._second == 0:
self._second = 60
if self._minute != 0:
self._minute -= 1
else :
self._minute = 59
if self._hour == 0:
self._hour = 23
else:
self._hour -= 1
def show(self):
"""显示时间"""
return '%02d:%02d:%02d' % \
(self._hour, self._minute, self._second)
def main():
t = time.localtime()
clock = Clock(t.tm_hour, t.tm_min,t.tm_sec)
while True:
print(clock.show())
sleep(1)
clock.run()
if __name__ == '__main__':
main()