I am making a simple python program to work as a rubiks cube timer. It uses the click library but I don't think that has to do with the problem. When I finish the program and run through the loop, it does not run my program again.
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
And this is what happens in my terminal
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)
So everytime I hit y it just goes to that if block. Why is this and how can I fix it?