|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 1314xxxxxx 于 2017-6-17 10:31 编辑
简单定制
知识点:
1、time模块中的函数localtime,perf_counter。
2、额,这节课好像都是实战,没什么知识点。。。
算了,放代码。
出来吧,代码虾!
- import time as t
- class MyTimer:
-
-
- def __init__(self):
- self.begin = 1
- self.end = 0
- self.no = ["年","月","天","小时","分钟","秒"]
- self.strtime = "未开始计时!"
- def __add__(self,other):
- strtime = "总共运行了"
- lased = []
- for index in range(6):
- lased.append(self.lasted[index] + other.lasted[index])
- def __str__(self):
- return self.strtime
- __repr__ = __str__
- def start(self):
- self.begin = t.perf_counter ()
- print("开始计时......")
- self.strtime = "总共运行了"
- def stop(self):
- self.end = t.perf_counter()
- self._calc()
- print("结束计时......")
- def _calc(self):
- if self.begin != 0:
- self.strtime += str(self.end - self.begin)
- print(self.strtime)
- self.begin = 1
- self.no = ["年","月","天","小时","分钟","秒"]
- self.strtime = "未开始计时!"
- self.end = 0
-
- else:
- print("请先使用start方法开始计时!")
复制代码
这是把课后作业加上课堂上的整合了起来的,不过,还没写课后作业的同学别看答案哦。 |
评分
-
查看全部评分
|