【Python】打字训练 2.0!
本帖最后由 ckblt 于 2022-2-9 12:44 编辑前几天,我做了一个打字训练的软件,
它能帮助你打字更快、更准确。
(金山打字难道不比它强?{:10_255:} )
更新内容:
[*]改进了代码
[*]新增抄词语模式
点我跳转到 【打字训练 1.0】
废话少说,上代码!{:10_279:}
"""
这是一款打字机软件,
它能帮助你打字更快、更准确。
注: 如果你使用此软件报错, 请把解释器换成 Python 3.10
"""
import random
from random import choice
import time
def mode_1():# 抄句子
def gen_sentence():
name = [
"我",
"太空人",
"太空狼",
"爷爷",
"奶奶",
"爷爷奶奶",
"喜之郎果冻",
"喜之郎",
"洗只狼",
"爸爸",
"妈妈",
"世界冠军",
"世界吃人冠军",
"世界吃狼冠军",
"航天飞机",
"太空",
"世界足球先生",
"世界",
"足球",
"世界杯",
"发明家",
"药",
"狼",
"狼人",
]
action = ["吃", "喝", "当", "画", "鼓励", "旅游", "踩"]
adj = ["高兴", "伤心", "当人", "生气", "美丽"]
return f"{choice(name)}{choice(['','长大了'])}要{choice(action)}{choice(name)},{choice(name)}可{choice(adj)}了,给{choice(name)}爱{choice(action)}的{choice(name)}。"
right = 0
wrong = 0
times = []
print("喜之郎果冻笑话 (请使用中文符号)")
print()
while True:
time.sleep(2)
print("请输入以下句子 ( 输入 0 退出 )")
sentence = gen_sentence()
print(sentence)
start = round(time.time(), 2)
answer = input()
end = round(time.time(), 2)
t = round(end - start, 2)
if answer == "0":
break
elif answer == sentence:
print(f"你对了, 用时 {t} 秒")
print()
times.append(t)
right += 1
else:
print(f"你错了, 用时 {t} 秒")
print()
times.append(t)
wrong += 1
if len(times) != 0:
print(
f"你对了 {right} 个, 错了 {wrong} 个, 平均速度是 {round(sum(times) / len(times), 2)} 秒"
)
print()
def mode_2():# 抄验证码
right = 0
wrong = 0
times = []
while True:
time.sleep(2)
print("请输入以下验证码 ( 输入 0 退出 )")
code = str(random.randint(100000, 999999))
print(code)
start = round(time.time(), 2)
answer = input()
end = round(time.time(), 2)
t = round(end - start, 2)
if answer == "0":
break
elif answer == code:
print(f"你对了, 用时 {t} 秒")
print()
times.append(t)
right += 1
else:
print(f"你错了, 用时 {t} 秒")
print()
times.append(t)
wrong += 1
if len(times) != 0:
print(
f"你对了 {right} 个, 错了 {wrong} 个, 平均速度是 {round(sum(times) / len(times), 2)} 秒"
)
print()
def mode_3():# 抄词语
right = 0
wrong = 0
times = []
words = "你好,红色,橙色,黄色,绿色,青色,蓝色,紫色,呼唤,呼喊,救命,尤其,已知,一直,求解,春天,夏天,秋天,冬天,昨天,今天,明天,白天,黑天,每天,黑夜,警察,保安,奔驰,奔跑,走路,吉他,小提琴,中提琴,大提琴,低音提琴,音乐,钢琴,竖琴,离职,理智,励志,荔枝,立志,例子,打字,沙子,泥土".split(
","
)
time.sleep(2)
while True:
time.sleep(0.5)
print("请输入以下词语 ( 输入 0 退出 )")
word = choice(words)
print(word)
start = round(time.time(), 2)
answer = input()
end = round(time.time(), 2)
t = round(end - start, 2)
if answer == "0":
break
elif answer == word:
print(f"你对了, 用时 {t} 秒")
print()
times.append(t)
right += 1
else:
print(f"你错了, 用时 {t} 秒")
print()
times.append(t)
wrong += 1
if len(times) != 0:
print(
f"你对了 {right} 个, 错了 {wrong} 个, 平均速度是 {round(sum(times) / len(times), 2)} 秒"
)
print()
if __name__ == "__main__":
choose_correct = True
modes = {"抄句子": mode_1, "抄验证码": mode_2, "抄词语": mode_3}
print("欢迎来到 TypeWriter 打字训练 2.0")
print()
while True:
if choose_correct:
print("请选择模式 ( 输入 0 退出 )")
for i in range(len(modes)):
print(i + 1, ". ", [*modes.keys()], sep="")
print()
try:
mode = int(input("选择: "))
print()
choose_correct = True
if mode == 0:
raise KeyboardInterrupt
elif mode <= len(modes):
modes[[*modes.keys()]]()
else:
raise ValueError("Invalid mode")
except ValueError:# 选择有误
choose_correct = False
print("你的选择有误, 请重新", end="")
# 之后他会 mode = int(input("选择: ")) , 也就是输出 "你的选择有误, 请重新选择: "
except KeyboardInterrupt:# 用户退出 或者 用户 Ctrl+C
print("感谢使用!")
exit()
如果您喜欢这个软件,可以给我评分哦~{:10_254:}
这些代码我以后会继续完善,有BUG可以提出哦~{:10_279:} {:10_256:}发现一个bug,在选择模式的时候输入0会进入抄词语模式。 要是是tkinter的更好{:10_256:}
页:
[1]