Ejemplo 1: python cómo hacer un cronómetro
import time
import sys
time_start = time.time()
seconds = 0
minutes = 0
running = True
while running:
try:
sys.stdout.write("r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
sys.stdout.flush()
time.sleep(1)
seconds = int(time.time() - time_start) - minutes * 60
if seconds >= 60:
minutes += 1
seconds = 0
except KeyboardInterrupt as e:
running = False
Ejemplo 2: cronómetro de Python
1 # latest_tutorial.py
2
3 import time
4 from reader import feed
5
6 def main():
7 """Print the latest tutorial from Real Python"""
8 tic = time.perf_counter()
9 tutorial = feed.get_article(0)
10 toc = time.perf_counter()
11 print(f"Downloaded the tutorial in {toc - tic:0.4f} seconds")
12
13 print(tutorial)
14
15 if __name__ == "__main__":
16 main()
Ejemplo 3: cómo hacer un cronómetro en pythoon
import time
now = time.time()
future = now + 10
while time.time() < future:
# do stuff
pass
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)