猫史档案馆


【Python作品分享】打印当前时间【作品秀】

用户:今的风儿甚为喧嚣今的风儿甚为喧嚣查看:0 回复:0 评论:0 创建时间:2019-09-23T20:02:25


【作品展示】

center_image

 

【作品介绍】

之前的计时因在线版的局限性没有做清屏,在这里我对代码进行了改进,增加了清屏功能,并修改为显示当前时间

 

【作品源代码】

import os,time

one_List = [
    [0, 0, 1],
    [0, 0, 1],
    [0, 0, 1],
    [0, 0, 1],
    [0, 0, 1],
]
two_List = [
    [1, 1, 1],
    [0, 0, 1],
    [1, 1, 1],
    [1, 0, 0],
    [1, 1, 1],
]
three_List = [
    [1, 1, 1],
    [0, 0, 1],
    [1, 1, 1],
    [0, 0, 1],
    [1, 1, 1],
]
four_List = [
    [1, 0, 1],
    [1, 0, 1],
    [1, 1, 1],
    [0, 0, 1],
    [0, 0, 1],
]
five_List = [
    [1, 1, 1],
    [1, 0, 0],
    [1, 1, 1],
    [0, 0, 1],
    [1, 1, 1],
]
six_List = [
    [1, 1, 1],
    [1, 0, 0],
    [1, 1, 1],
    [1, 0, 1],
    [1, 1, 1],
]
seven_List = [
    [1, 1, 1],
    [0, 0, 1],
    [0, 0, 1],
    [0, 0, 1],
    [0, 0, 1],
]
eight_List = [
    [1, 1, 1],
    [1, 0, 1],
    [1, 1, 1],
    [1, 0, 1],
    [1, 1, 1],
]
nine_List = [
    [1, 1, 1],
    [1, 0, 1],
    [1, 1, 1],
    [0, 0, 1],
    [1, 1, 1],
]
zero_List = [
    [1, 1, 1],
    [1, 0, 1],
    [1, 0, 1],
    [1, 0, 1],
    [1, 1, 1],
]
point_List = [
    [0, 0, 0],
    [0, 1, 0],
    [0, 0, 0],
    [0, 1, 0],
    [0, 0, 0],
]
Time_List = [zero_List,one_List,two_List,three_List,four_List,five_List,six_List,seven_List,eight_List,nine_List]

#时间转化
def Time(time):
    h = time//3600
    m = time % 3600//60
    s = time % 3600 % 60
    return h, m, s

#将时间拆分
def split_num(num):
    num_1 = num // 10
    num_2 = num % 10
    return num_1,num_2

#创建时间列表
def time_List_creator(time):
    time_List = [[0]*22]*5
    # HMS = []
    # for i in range(3):
    #     HMS = HMS + list(split_num(time[i]))
    # print(HMS)
    hour_1, hour_2 = split_num(time[0])
    minute_1, minute_2 = split_num(time[1])
    second_1, second_2 = split_num(time[2])
    for i in range(5):
        time_List[i] = Time_List[hour_1][i]+[0]+Time_List[hour_2][i]+point_List[i]+Time_List[minute_1][i] + \
            [0]+Time_List[minute_2][i]+point_List[i] + \
            Time_List[second_1][i]+[0]+Time_List[second_2][i]
    return time_List

#根据列表绘制图形
def draw(List):
    for i in range(len(List)):
        for j in range(len(List[i])):
            if List[i][j] == 0:
                print("  ", end="")
            elif List[i][j] == 1:
                print("██", end="")
        print("\n", end="")


# print(m(), n())
# Time_min = 0
# Time_max = int(input("请输入本局游戏时长"))
# while Time_min < Time_max:
#     os.system("cls")
#     draw(time_List_creator(Time(Time_min)))
#     # print(time_List_creator(Time(Time_min)))
#     # print(Time(Time_min))
#     # print('本局游戏已进行{}小时{}分钟{}秒'.format(h, m, s))
#     time.sleep(1)
#     Time_min += 1


# for i in range(Time_max):
#     os.system("cls")
#     draw(time_List_creator(Time(Time_max)))
#     time.sleep(1)
#     Time_max -= 1
import datetime

while True:
    os.system("cls")
    h = int(str(datetime.datetime.now())[11:13])
    m = int(str(datetime.datetime.now())[14:16])
    s = int(str(datetime.datetime.now())[17:19])
    list_datetime = [h,m,s]
    draw(time_List_creator(list_datetime))
    # time.sleep(0.1)

# while True:
#     os.system("cls")
#     draw(time_List_creator(Time(Time_min)))

# print("Game Over")

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页