第一天接触类的知识,尝试使用其写一个数字时钟
import time
class shijian(object):
def __init__(self,hour,min,sec):
self.hour = hour
self.min = min
self.sec = sec
def juti(self):
while True:
t = '0'
for h in range(self.hour,24):
h = str(h)
if int(h) < 10:
h = t + h
for m in range(self.min,60):
m = str(m)
if int(m) < 10:
m = t + m
for s in range(self.sec,60):
s = str(s)
if int(s) < 10:
s = t + s
time.sleep(1)
print(h + ':' + m + ':' + s)
self.hour = 0
self.min = 0
self.sec = 0
it = shijian(23,59,56)
it.juti()
实现结果:
23:59:56
23:59:57
23:59:58
23:59:59
00:00:00
00:00:01
00:00:02
00:00:03