我正在用python写倒计时,但它不起作用。
for countdown in 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, quit():
print (countdown)这就是密码。倒计时只是放大和退出程序。是否有办法使倒计时符合实时和倒计时,并在10秒内退出。不是马上。
发布于 2015-07-08 01:04:07
您需要告诉它等待,否则它将以您的处理器所能完成的速度运行代码。
from time import sleep
for countdown in range(10,0,-1):
print(countdown)
sleep(1)发布于 2015-07-08 01:04:04
tl;博士python缓冲器打印,python没有那么慢
import sys, time
for countdown in range(10,1,-1):
print(countdown)
sys.stdout.flush() #flushes buffer
time.sleep(1) #sleep for one second, otherwise loop goes very quickly
print(0)
sys.stdout.flush()
# no quit needed. Program will end when file endshttps://stackoverflow.com/questions/31281854
复制相似问题