python 简单的倒计时程序
自定一个 stopWathc(m, s) 函数,m 表示分钟数, s 表示秒数。调用此函数,经过指定的时间后播放提示音乐。
代码:
import time, subprocess
def stopWatch(m, s):
timeLeft = 60*m + s
while timeLeft > 0:
print(timeLeft, end='')
time.sleep(1)
timeLeft -= 1
#倒计时结束,播放提示音乐。
subprocess.Popen(['start', 'alarm.mp3'], shell=True)
非学无以广才,非志无以成学。