1 Star 2 Fork 2

刘彬彬/小知识_自动化任务脚本_DhanushNehru

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
timer.py 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
Aakash Kotha 提交于 3年前 . Create timer.py
import time
def countdownTimer():
# get the number of seconds
no_of_secs = int(input('How many seconds?: '))
while no_of_secs:
if no_of_secs < 60:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = no_of_secs // 60
secs = no_of_secs % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
elif 60 <= no_of_secs < 3600:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = no_of_secs // 60
secs = no_of_secs % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
elif 3600 <= no_of_secs <= 86400:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = (no_of_secs % 3600) // 60
secs = (no_of_secs % 3600) % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
print('Time Up!')
countdownTimer()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/liu_binbin/some_python_scripts.git
git@gitee.com:liu_binbin/some_python_scripts.git
liu_binbin
some_python_scripts
小知识_自动化任务脚本_DhanushNehru
master

搜索帮助