ent = input("Press the Enter key to spin the roulette wheel.")
if ent == "":
print("Roulette wheel spinning...")
print("Roulette wheel spinning...")
else:
#I want it to do nothing till only enter is hit What can I write here?
有没有办法让当按下除 Enter 之外的其他键时,它不会执行任何操作,直到只按下 Enter 为止?使用输入允许用户写一些东西,因此当他们按下回车键时,它总是会运行。如果我可以禁用写入并且仅在按下回车键时才响应,我会更喜欢它。
最佳答案
您可以在输入周围放置一个 while 循环,以便在输入等于 Enter 之前用户无法继续。例如:
while True:
ent = input("Press the Enter key to spin the roulette wheel.")
if ent == "":
break
print("Roulette wheel spinning...")
print("Roulette wheel spinning...")
希望这能有所帮助。
关于python - 如何让程序只有在按下回车键时才继续运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54936903/