【发布时间】:2017-07-06 20:04:13
【问题描述】:
我是一个初学者,所以请原谅我的无知。
我想要做的基本上是从用户那里得到一个输入,要么是从 1 到 9 的数字,要么是一个空格。我通过浏览这个网站想出了一些代码,我认为这些代码应该可以工作,但不能。当我尝试运行它时,它什么也不做,没有错误消息或任何东西。
import msvcrt
numInput = 0
while numInput == 0 :
if msvcrt.kbhit():
if msvcrt.getch() == "1":
numInput = "1"
elif (msvcrt.getch() == "2"):
numInput = "2"
elif (msvcrt.getch() == "3"):
numInput = "3"
elif (msvcrt.getch() == "4"):
numInput = "4"
elif (msvcrt.getch() == "5"):
numInput = "5"
elif (msvcrt.getch() == "6"):
numInput = "6"
elif (msvcrt.getch() == "7"):
numInput = "7"
elif (msvcrt.getch() == "8"):
numInput = "8"
elif (msvcrt.getch() == "9"):
numInput = "9"
elif (msvcrt.getch() == " "):
numInput = " "
【问题讨论】:
-
正如 [this] (stackoverflow.com/questions/16076853/…) 讨论中所述。你必须从控制台运行这个程序。
-
您是否在 Windows 上通过命令提示符运行此程序?