import msvcrt
x: int = 0
while not msvcrt.getch() == ' ':
if x <= 10000:
print(x)
x += x
else:
print("space")当按下“空格”时,循环不会停止。
发布于 2018-12-07 08:37:58
msvcrt.getch()返回一个字节字符串,而不是字符串,因此当您按空格键时,它将返回b' ',而不是' '。
因此,更改:
while not msvcrt.getch() == ' ':至:
while not msvcrt.getch() == b' ':发布于 2018-12-07 09:53:26
import msvcrt
x = 0
while not msvcrt.getch() == b' ':
if x <= 10000:
print(x)
x += 1
else:
print("space")感谢您的关注
https://stackoverflow.com/questions/53661655
复制相似问题