python写的计数器

import time as t

class MyTimer():
    def __str__(self):
        return self.prompt
    __repr__=__str__
    #开始计时
    def start(self):
        self.start=t.localtime()
        print("计时开始时...")

        #停止计时
    def stop(self):
        self.stop=t.localtime()
        self._calc()
        print("计时结束!")


        
    #内部方法,计算运行时间
    def _calc(self):
        self.lasted=[]
        self.prompt='总共运行了,,'
        for index in range(6):
            self.lasted.append(self.stop[index]-self.start[index])
            self.prompt+=str(self.lasted[index])

        
运行结果:

猜你喜欢

转载自blog.csdn.net/weixin_39338645/article/details/82856013
今日推荐