Repetition is not equivalent to one second

Asked

Viewed 89 times

4

How much would be the limit value for a repeat to be compared to a second? For example:

for x in range(0, 1000):
    print("1 segundo")

4 answers

5


There is no way to make this prediction even because each computer will take a completely different time, worsens the fact that there is IO in the operation. You can put the process to sleep for a second. Almost always you don’t want to do this and it doesn’t make much sense except for specific tests or some very niched problem. It would be something like this:

import time

time.sleep(1)

I put in the Github for future reference.

1

You can use the time.sleep() to perform an iteration with a given estimated time.

import time

for i in range(0, 3):
    time.sleep(1)
    print "Hello World"

This code snippet will print the Hello World 3 times, each iteration will be executed after 1 second.

0

There is because it depends on your computer what you can do is, using the time library with import time add a time.sleep(1) or calculate differences in time.clock() to mark runtime and do as you wish

-1

For your case you may care the 'team' that will serve as a chronometer

Ao invés de 

for x in range(0, 1000):
    print("1 segundo")


Nós podemos usar:

import time

for x in range(0, 1000):
    time.sleep(1)
    print("1 segundo")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.