python也玩私人定制。一个小的计时器

import time as t
class Time():    
    def __str__(self):        
    return  self.prompt    
__repr__ = __str__    
def __iadd__(self, other):        
    tips='相加后共运行了'        
    result = []       
    print(other.lasted)        
    print(self.lasted)        
    for index in range(6):            
    result.append(self.lasted[index] + other.lasted[index])                                                  
    print(index)            
    if result[index]:                
         tips +=(str(result[index])+self.un[index])       
         return tips   
 #      定义参数    
def __init__(self):       
    self.begin = 0        
    self.end = 0        
    self.lasted = []        
    self.prompt = '还没开始即使啦。先用start好吗?'        
    self.un=['年','月','日','时','分','秒']
# 开始计时    
def start(self):              
    self.gegin = t.localtime()        
    print('开始计时')
#结束计时    
def stop(self):            
    self.end = t.localtime()            
    if self.begin == 0:                
          print('请先调用start()方法!!!')           
    else:               
          self.calc()                
          print('停止计时')#计算运行时间    
def calc(self):        
    self.prompt = '总共运行了'        
    lasted = []        
    for index in range(6) :            
    lasted.append(self.end[index]-self.begin[index])            
    if lasted[index]:                
          self.prompt += (str(lasted[index]) + self.un[index])                        
          print(list(lasted))       
    self.begin=0        
    self.end=0

你可能感兴趣的:(python也玩私人定制。一个小的计时器)