gpt4 book ai didi

python - While 循环未检测到 msvcrt.getch() 按键

转载 作者:行者123 更新时间:2023-12-01 08:37:01 24 4
gpt4 key购买 nike

import msvcrt
x: int = 0
while not msvcrt.getch() == ' ':
if x <= 10000:
print(x)
x += x
else:
print("space")

按下“空格”时循环不会停止。

最佳答案

msvcrt.getch() 返回字节串而不是字符串,因此当您按空格键时,它将返回 b' ',而不是 ' '.

因此改变:

while not msvcrt.getch() == ' ':

致:

while not msvcrt.getch() == b' ':

关于python - While 循环未检测到 msvcrt.getch() 按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53661655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com