1# Create a stopwatch
2
3# Import a module called as time
4
5import time
6
7# create all the variables
8
9day = 0
10hour = 0
11min = 0
12sec = 0
13
14# Display the headings
15
16print("D - H - M - S")
17print()
18
19# Create an infinite loop
20
21while True:
22
23 # Create the main part of the stopwatch
24
25 time.sleep(1)
26
27 if sec == 59:
28 sec = -1
29 min = min + 1
30
31 sec = sec + 1
32 if min == 60:
33 min = 0
34 hour = hour + 1
35
36 if hour == 24:
37 hour = 0
38 day = day + 1
39 print(day, "-", hour, "-", min, "-", sec)
40
1import time
2
3time_to_stop = 10 #seconds
4for x in range(1, time_to_stop+1):
5 print(x)
6 time.sleep(1)
1import time
2import sys
3
4time_start = time.time()
5seconds = 0
6minutes = 0
7
8running = True
9
10while running:
11 try:
12 sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
13 sys.stdout.flush()
14 time.sleep(1)
15 seconds = int(time.time() - time_start) - minutes * 60
16 if seconds >= 60:
17 minutes += 1
18 seconds = 0
19 except KeyboardInterrupt as e:
20 running = False
1 1 # latest_tutorial.py
2 2
3 3 import time
4 4 from reader import feed
5 5
6 6 def main():
7 7 """Print the latest tutorial from Real Python"""
8 8 tic = time.perf_counter()
9 9 tutorial = feed.get_article(0)
1010 toc = time.perf_counter()
1111 print(f"Downloaded the tutorial in {toc - tic:0.4f} seconds")
1212
1313 print(tutorial)
1414
1515 if __name__ == "__main__":
1616 main()
17
1
2
3import time
4
5now = time.time()
6future = now + 10
7while time.time() < future:
8 # do stuff
9 pass