Python练习题-010

题目-010:暂停一秒输出,并格式化当前时间。

  • 分析使用 time 模块的相关函数
  • Python版本:Python 3.6.5

   代码1:不妨对倒计时函数改装,改成如下:

def countdown(t=60):
    print("-*- Countdown start -*-")
    for i in range(t,0,-1):
        print("Countdown:%d"%i)
        print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
        time.sleep(1)
    print("-*- Countdown End A-*-")

countdown(5)
-*- Countdown start -*-
Countdown:5
2018-07-04 14:22:56
Countdown:4
2018-07-04 14:22:57
Countdown:3
2018-07-04 14:22:58
Countdown:2
2018-07-04 14:22:59
Countdown:1
2018-07-04 14:23:00
-*- Countdown End -*-


你可能感兴趣的:(python)