Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you probably looking for this %

# when the remainder of t divided by 1000 equals zero
if t % 1000 == 0:
    print(kounter)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading