import random
from threading import Timer
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
score = 0
list = ("Toothpaste", "Seashell", "Binder", "Computer", "Laptop", "Tablet", "Turing", "Python", "Circuit")
list2 = ("Mathematics", "Onomatopoeia", "Obnoxious", "Archiving", "Licencing")
endgame = 0
def printbob():
print("you lose bro")
endgame = 1
def boys():
points = 0
while(score >= 0):
timeout = 3
timer = Timer(timeout, printbob)
timer.start()
if(points < 5):
cs = random.choice(list)
else:
cs = random.choice(list2)
print("Type this sentence:", color.GREEN + cs + color.END)
user = "You have %d seconds to choose the correct answer...\n" % timeout
answer = input(user)
timer.cancel()
if (answer == cs) and (endgame == 0):
print("Nice")
points += 1
else:
print("Bye")
exit()
boys()
これは、リストから選択した単語を印刷するプログラムで、拘束時間内に完全に同じ単語を印刷する必要があります。入力がない場合、コードが入力を待っているので終了しないという問題があります。Pythonでタイピングゲームを作成する(タイマー、マルチスレッド、def()など)
要するに、入力がないときにプログラムが終了するようにコードを調整するにはどうすればいいですか?
ありがとう、 Robert Daniro
編集:誰かがコメントしただけで彼に返信しましたが、彼はコメントや何かを削除しました。 – RobertDaniro