I\'m trying to ucreate a timer function that runs in the background of my code and make it so I can use/check the time. What I mean by use/check, I\'m trying to make it so I can
The problem with your code is that when you run hall()
, Python first executes the whole of timer()
(i.e. the whole for
loop), and then moves on with the rest of the code (it can only do one thing at a time). Thus, by the time it reaches the while
loop in hall()
, timer
is already 0
.
So, you're going to have to do something about that timer
so that it counts down once, and then it moves on to the do something
part.
Something that you can do is this:
def hall():
for a in range(0, 15):
print(15 - a)
# do something
time.sleep(1)
This should work just fine (if you're only executing hall
15 times), and condenses your code to just one function.