我正在製作一個簡單的python程序作爲rubiks立方體計時器。它使用點擊庫,但我不認爲這與問題有關。當我完成程序並運行循環時,它不會再運行我的程序。Python循環錯誤
import click
import time
import sys
print("CubeTimer 1.0")
print("Press the spacebar to start the timer")
stillTiming = True
while stillTiming:
key = click.getchar()
if key == ' ':
print('starting timer')
# start timer
t0 = time.time()
newKey = click.getchar()
if newKey == ' ':
# stop timer
print('stopping timer')
t1 = time.time()
total = t1 - t0
print(total)
elif key =='esc':
sys.exit()
print('Time again? (y/n)')
choice = click.getchar()
if choice == 'y':
stillTiming = True
else:
stillTiming = False
而且這是在我的終端
CubeTimer 1.0
Press the spacebar to start the timer
starting timer
stopping timer
2.9003586769104004
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
Time again? (y/n)
所以每次我打了會發生什麼Ÿ它只是去,如果塊。爲什麼會這樣,我該如何解決它?