【发布时间】:2017-10-22 12:01:55
【问题描述】:
from time import sleep
alive = True
while alive == True:
print("You have awoken in a unknown land.")
sleep(2)
print("\nDo you go north, south, east or west?")
print("Press the up arrow to go north.")
print("Press the down arrow to go south.")
print("Press the left arrow to go west.")
print("Press the right arrow to go east.")
input(" ")
如何让用户按下其中一个箭头键并让程序继续运行而不需要按 Enter 键?
提前致谢!
~洛伦佐
【问题讨论】:
-
哪个操作系统?
msvcrt.getch可用,但仅在 Windows 上可用。 -
这可能比你想象的要复杂。例如,您可以看到here。从您的示例代码来看,您会发现通过接受“N、E、S、W”作为输入更容易推进您的项目。
-
谢谢凯文,但我想让它对电脑世界的新手更友好一点,找到箭头比 N、E、S 和 W 键容易得多。不过只是个人喜好。 :)
-
凯文没有建议,我建议。为了简单起见,我建议您暂时使用这些字母。我假设您正在学习 Python(
while alive == True:只是while alive:而您的input可能不会做任何事情,因为它没有分配给任何东西)。我认为你会更容易(目前)继续前进,而无需为此苦苦挣扎。
标签: python python-3.x input