Deepseek-R1 AI大模型写的一段程序
请用Python写一个数字时钟,以字符方式显示当前时间,在原位置每秒刷新一次数字。
import time
import os
# 字符艺术表示的大数字(放大5倍)
DIGITS = {
'0': [
" ##### ",
" ## ## ",
"## ##",
"## ##",
"## ##",
" ## ## ",
" ##### "
],
'1': [
" ## ",
" #### ",
" ## ",
" ## ",
" ## ",
" ## ",
" ###### "
],
'2': [
" ####### ",
"## ##",
" ##",
" ####### ",
"## ",
"## ",
" ########"
],
'3': [
" ####### ",
"## ##",
" ##",
" ####### ",
" ##",
"## ##",
" ####### "
],
'4': [
"## ##",
"## ##",
"## ##",
" ########",
" ##",
" ##",
" ##"
],
'5': [
" ####### ",
"## ",
"## ",
" ####### ",
" ##",
"## ##",
" ####### "
],
'6': [
" ####### ",
"## ",
"## ",
" #######",
"## ##",
"## ##",
" ####### "
],
'7': [
"########",
" ##",
" ##",
" ## ",
" ## ",
" ## ",
" ## "
],
'8': [
" ####### ",
"## ##",
"## ##",
" ####### ",
"## ##",
"## ##",
" ####### "
],
'9': [
" ####### ",
"## ##",
"## ##",
" ####### ",
" ##",
"## ##",
" ####### "
],
':': [
" ",
" ",
" ## ",
" ",
" ## ",
" ",
" "
]
}
def print_large_time(time_str):
lines = [''] * 7
for char in time_str:
if char in DIGITS:
for i, line in enumerate(DIGITS[char]):
lines[i] += line + ' '
else:
for i in range(7):
lines[i] += ' '
return lines
def clear_screen():
# 根据操作系统清除屏幕
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
def display_clock():
while True:
# 获取当前时间
current_time = time.strftime('%H:%M:%S')
# 清除屏幕
clear_screen()
# 打印大字时间
large_time_lines = print_large_time(current_time)
for line in large_time_lines:
print(line)
# 等待一秒钟
time.sleep(1)
display_clock()(交互过程省略一千字……)
运行效果图:


