Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print the value at each t=1000 in a way better than the following?

Consider:

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)   

Now the above code in itself might be written in an infinitely better way but that is just to show what I want to do in my actual code in which I want to print the value of a variable at each 1000 step till the end (note in above I did it only till 6000 but I want it till 10,000) which looks absurd if the end time is very large.

I am sure there is a prettier and more efficient way of doing it.

like image 343
Lost Avatar asked Dec 03 '25 17:12

Lost


1 Answers

you probably looking for this %

# when the remainder of t divided by 1000 equals zero
if t % 1000 == 0:
    print(kounter)
like image 64
Hanna Avatar answered Dec 05 '25 10:12

Hanna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!