I trying to create a timer for my quiz game. It should reset after every right question. But problem with my code is that it keeps increasing speed after every time it resets.
timeCount = 30
def countdown():global timeCountwhile timeCount > 0:print(timeCount)sleep(1)timeCount -= 1else:print("Time Out!")
I think this is what you are trying to do:
import timetimeCount = 30
start = time.time()
seconds = 0
def countdown():global timeCountglobal secondswhile seconds < timeCount:now = time.time()seconds = now - startprint(timeCount - seconds)else:print("Time Out!")countdown()
This teaches you how to use time.time. You can take away seconds
from timeCount
to make a timer that goes down from 30 to 0. When the seconds
hits 30, you can end the loop and print "Time out". You can truncate the unnecessary floating point values, since i am assuming floating point numbers doesn't look good on a quiz timer and is unnecessary as well.
seconds = int(seconds)