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
1
2
3import time
4
5now = time.time()
6future = now + 10
7while time.time() < future:
8 # do stuff
9 pass