Python 计时器没有按我希望的方式工作

Python timer is not working as how I wanted it to work

我试图制作一个计时器,当变量达到 2502 时它会打印东西,但它不是在特定时间执行它,而是一次打印所有内容,我不知道如何修复它。

n1 = str(",..")
n2 = str(".,.")
n3 = str("..,")
print(n1)
timer = 2
while timer < 2502:
    timer += 1
if timer == int("2502"):
    print(n2)
timer2 = 2
while timer2 < 2502:
    timer2 += 1
if timer2 == int("2502"):
    print(n3)

您可以在 while 循环中插入时间延迟。 (我减少了一点检查程序的时间)

import time  # import the module
n1 = str(",..")
n2 = str(".,.")
n3 = str("..,")
print(n1)
timer = 2
while timer < 10: 
    time.sleep(1) # will do nothing for one second
    timer += 1
if timer == int("10"):
    print(n2)
timer2 = 2
while timer2 < 10:
    time.sleep(1) # will do nothing for one second
    timer2 += 1
if timer2 == int("10"):
    print(n3)