我正在尝试为倒数计时器创建一个代码保持原位:这样每行都会覆盖前一行.这是我到目前为止:
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)
为什么回车似乎不起作用?