import msvcrt
x: int = 0
while not msvcrt.getch() == ' ':
if x <= 10000:
print(x)
x += x
else:
print("space")
Loop is not stopping when the "space" is pressed.
import msvcrt
x: int = 0
while not msvcrt.getch() == ' ':
if x <= 10000:
print(x)
x += x
else:
print("space")
Loop is not stopping when the "space" is pressed.
msvcrt.getch()
returns a bytestring rather than a string so when you press space it will return b' '
, not ' '
.
Therefore change:
while not msvcrt.getch() == ' ':
To:
while not msvcrt.getch() == b' ':
import msvcrt
x = 0
while not msvcrt.getch() == b' ':
if x <= 10000:
print(x)
x += 1
else:
print("space")
thanks for your interests