小编GM.*_*ost的帖子

回车不在IDLE工作?

我正在尝试为倒数计时器创建一个代码保持原位:这样每行都会覆盖前一行.这是我到目前为止:

import time

def countdown(t):
    while t:
        mins, secs = divmod(t, 60)
        timeformat = "{:02d}:{:02d}".format(mins, secs)
        print(timeformat, end='\r')
        time.sleep(1)
        t -= 1
    print("That's the end! You lose...\n\n\n\n\n")
    exit()

countdown(10)
Run Code Online (Sandbox Code Playgroud)

但是,输出是:

00:10
00:09
00:08
...
00:00
That's the end! You lose...
Run Code Online (Sandbox Code Playgroud)

为什么回车似乎不起作用?

python python-idle python-3.x

5
推荐指数
2
解决办法
3409
查看次数

标签 统计

python ×1

python-3.x ×1

python-idle ×1