Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在不按enter键的情况下输入输入_Python_Python 3.x - Fatal编程技术网

Python 如何在不按enter键的情况下输入输入

Python 如何在不按enter键的情况下输入输入,python,python-3.x,Python,Python 3.x,比如说我希望是这样, x = int(input("Please enter your guess :") If x = 1: Print ("correct") 尽管每次我都需要按enter键,我如何才能使其在按键时读取 我确实找到了getch(),尽管我无法让它工作。在Windows中,您可以使用msvcrt。在其他系统上,这有点困难,请查看以下配方: 您可以这样使用它: getch = _Getch() print 'Please enter your guess: ' x =

比如说我希望是这样,

x = int(input("Please enter your guess :")
If x = 1:
   Print ("correct")
尽管每次我都需要按enter键,我如何才能使其在按键时读取


我确实找到了getch(),尽管我无法让它工作。

在Windows中,您可以使用
msvcrt
。在其他系统上,这有点困难,请查看以下配方:

您可以这样使用它:

getch = _Getch()

print 'Please enter your guess: '
x = getch()

if (int(x) == 1):
    print 'correct'
else:
    print 'wrong'

在Windows中,您可以使用
msvcrt
。在其他系统上,这有点困难,请查看以下配方:

您可以这样使用它:

getch = _Getch()

print 'Please enter your guess: '
x = getch()

if (int(x) == 1):
    print 'correct'
else:
    print 'wrong'

虽然我希望有人能为我提供一个如何使用getch()的例子,但我还是仔细看过了getch()-就像在Windows和Unix上读取stdin中的无缓冲字符一样(Python配方),我确实仔细阅读了它,尽管我希望有人能为我的示例提供一个如何使用getch()的示例。-getch()-类似于在Windows和Unix上从stdin读取无缓冲字符(Python配方)