如何以比以下更好的方式打印每个 t=1000 处的值?

Los*_*ost 2 python for-loop if-statement

考虑:

dt=10**(-3)
for i in range(1,10**7+1):
    t=i*dt;
    kounter=e**(t*(dt**3))
    if t==1000 or t==2000 or t==3000 or t==4000 or t==5000 or t==6000:
        print(kounter)   
Run Code Online (Sandbox Code Playgroud)

现在上面的代码本身可能会以一种无限更好的方式编写,但这只是为了展示我想要在实际代码中做什么,其中我想在每 1000 步打印变量的值直到最后(请注意上面我只做到了 6000,但我想要直到 10,000)如果结束时间非常长,这看起来很荒谬。

我确信有一种更漂亮、更有效的方法来做到这一点。

小智 7

你可能正在寻找这个%

# when the remainder of t divided by 1000 equals zero
if t % 1000 == 0:
    print(kounter)
Run Code Online (Sandbox Code Playgroud)