|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time as t
class MyTimer:
def __init__(self):
self.begin = 0
self.end = 0
self.prompt = "before the time is running"
self.lasted = []
self.unit = ["year","month","day","hour","minute","second"]
self.word = ""
def __str__(self):
return self.prompt
__repr__ = __str__
def start(self):
self.begin = t.localtime()
print("the time is running!")
def stop(self):
if not self.begin:
print("You don't have run the method start")
print("Do you want me stat the method? if yes I will start if or I will quit ")
self.word = input("plz input yes or no:")
if self.word == "yes":
self.end = t.localtime()
print("the timer is end")
self._clac()
else:
print("The Timer is over")
raise KeyboardInterrupt
else:
self.end = t.localtime()
print("the timer is end")
self._clac()
# an inner method
def _clac(self):
self.prompt = "all of time is "
for index in range(6):
self.lasted.append(self.end[index] - self.begin[index])
if self.lasted[index] != 0:
self.prompt += str(self.lasted[index]) + " " + self.unit[index]
你设计的功能,自己start,由于你的begin还是0,不能用[]索引
|
|