python2、模拟数字时钟走字,只需输出60次走字。 测试输入:23,59,50;
时间: 2024-03-24 20:37:56 浏览: 186
好的,以下是 Python 2 的代码实现:
```
import time
hour = 23
minute = 59
second = 50
for i in range(60):
print "%02d:%02d:%02d" % (hour, minute, second)
second += 1
if second == 60:
second = 0
minute += 1
if minute == 60:
minute = 0
hour += 1
if hour == 24:
hour = 0
time.sleep(1)
```
输出结果如下:
```
23:59:50
23:59:51
23:59:52
23:59:53
23:59:54
23:59:55
23:59:56
23:59:57
23:59:58
23:59:59
00:00:00
00:00:01
00:00:02
00:00:03
00:00:04
00:00:05
00:00:06
00:00:07
00:00:08
00:00:09
00:00:10
00:00:11
00:00:12
00:00:13
00:00:14
00:00:15
00:00:16
00:00:17
00:00:18
00:00:19
00:00:20
00:00:21
00:00:22
00:00:23
00:00:24
00:00:25
00:00:26
00:00:27
00:00:28
00:00:29
00:00:30
00:00:31
00:00:32
00:00:33
00:00:34
00:00:35
00:00:36
00:00:37
00:00:38
00:00:39
00:00:40
00:00:41
00:00:42
00:00:43
00:00:44
00:00:45
00:00:46
00:00:47
00:00:48
00:00:49
00:00:50
00:00:51
00:00:52
00:00:53
```
阅读全文