3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
PYTHON機器學習自學/自修 整理[00024] ~ PYTHON – 100天从新手到大师(08.面向对象编程基础.md) 實作數字鐘類別(物件)範例 import sys import decimal#精準度/精度 運算 import random from os import system from time import sleep class Clock(object): """数字时钟""" def __init__(self, hour=0, minute=0, second=0): """初始化方法 :param hour: 时 :param minute: 分 :param second: 秒 """ self._hour = hour self._minute = minute self._second = second def run(self): """走字""" self._second += 1 if self._second == 60: self._second = 0 self._minute += 1 if self._minute == 60: self._minute = 0 self._hour += 1 if self._hour == 24: self._hour = 0 def show(self): """显示时间""" return 'd:d:d' % \ (self._hour, self._minute, self._second) def main(): clock = Clock(23, 59, 58) while True:#無窮迴圈 system('cls')#os模組 print(clock.show(), end="\r") sleep(1) clock.run() if __name__ == '__main__': main() #system('cls')只有在純命力模式有要,在IDE無效 #ptrhon test.py

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦