Reputation: 3514
Could someone give me a tip? I am attempting to create a countdown timer that will reset based on the episodes...
For example I was hoping this code below would countdown from 10 - 0, 15 times (total_episodes
) but it only counts down once... Any tips greatly appreciated..
import time
total_episodes = 15
n=10
for episode in range(total_episodes):
for i in range(n):
time.sleep(1)
n -= 1
print("countdown episode timer",n)
I need the time.sleep
as my real scenario I am trying to create something that will countdown 10 minutes for 15 times/episodes..
Upvotes: 0
Views: 613
Reputation: 9007
You're forgetting to reset your n
.
for episode in range(total_episodes):
n = 10 # do this
for i in range(n):
time.sleep(1)
n -= 1
print("countdown episode timer", n)
Without resetting your n
, the nested for
-loop will evaluate i in range(0)
which is just an empty range.
OR you could even do without the n
.
for episode in range(total_episodes):
for i in range(10, 0, -1):
time.sleep(1)
print("countdown episode timer", i)
Upvotes: 1