[英]Create a simple countdown timer Python
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.. 例如,我希望下面的这段代码可以从
total_episodes
倒数15次( total_episodes
),但是它只能倒数一次。
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.. 我需要
time.sleep
作为我的真实场景,我正在尝试创建将倒数10分钟(每集15次)的内容。
You're forgetting to reset your n
. 您忘记了重设
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. 在不重置
n
,嵌套for
-loop会i in range(0)
评估i in range(0)
这只是一个空范围。
OR you could even do without the n
. 或者你甚至可以做无
n
。
for episode in range(total_episodes):
for i in range(10, 0, -1):
time.sleep(1)
print("countdown episode timer", i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.