【发布时间】:2018-06-05 21:12:39
【问题描述】:
我正在制作一个打字速度测试游戏,并试图让它在用户输入 python input() 时,可以由他们在 Windows 上按空格而不是仅仅输入来提交。 我的代码类似于以下:
score = 0
start_time = int(time.time())
characters = 0
words = 0
current_word = random.choice(WORDS)
next_word = random.choice(WORDS)
while (int(time.time()) - start_time) <= TIME_LIMIT:
os.system('cls')
print(f"Your word is {current_word}")
print(f"The next word will be {next_word}")
print(f"Your current score is {score}")
attempt = input("> ")
if attempt.lower() == current_word.lower():
score = score + 1
words = words + 1
characters = characters + len(current_word)
current_word = next_word
next_word = random.choice(WORDS)
有没有办法让它工作,或者最好是创建我自己的输入函数?
【问题讨论】:
-
您确定要这样做吗?你不想在你的游戏中检查句子的输入速度吗?打字培训应用程序甚至提供完整的文本供用户输入。我的意思是,你需要空格键。
标签: python input key-bindings