(1)设计时间显示函数show(self)
(2)设计两个时间大小比较函数compare(self,t),其中t是另外一个时间。
建立一个时间类time,它包含huor,minute,second的实例属性
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2019-05-09 15:38关注
# -*- coding: UTF-8 -*- class time(object): def __init__(self, h=0, m=0, s=0): self.hour = h self.minute = m self.second = s def compare(self, t): if (self.hour == t.hour): if (self.minute == t.minute): if (self.second == t.second): return 0 else: return self.second - t.second else: return self.minute - t.minute else: return self.hour - t.hour def cmp2str(n): if (n == 0): return "=" elif (n < 0): return "<" else: return ">" t1 = time(2019, 3, 1) t2 = time(2019, 3, 20) t3 = time(2019, 5, 1) t4 = time(2019, 5, 1) print(cmp2str(t1.compare(t2))) print(cmp2str(t2.compare(t3))) print(cmp2str(t3.compare(t4))) print(cmp2str(t4.compare(t1)))
< < = >
解决 6无用 4
悬赏问题
- ¥15 安装svn网络有问题怎么办
- ¥15 Python爬取指定微博话题下的内容,保存为txt
- ¥15 vue2登录调用后端接口如何实现
- ¥65 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥15 latex怎么处理论文引理引用参考文献