-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_utilities.py
More file actions
29 lines (24 loc) · 798 Bytes
/
python_utilities.py
File metadata and controls
29 lines (24 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# The DisplayDuration function is used to correctly display the completion time of a function or program
# in hours, minutes and seconds, including the correct spelling of 'hour(s)', 'minute(s)' and 'second(s)'.
#
# The output is "Completed in xx hour xx minutes xx seconds."
def DisplayDuration(starttime, endtime):
m, s = divmod(int(endtime - starttime), 60)
h, m = divmod(m, 60)
duration = 'Completed in '
if h > 0:
if h > 1:
duration = duration + str(h) + ' hours '
else:
duration = duration + str(h) + ' hour '
if m > 0:
if m > 1:
duration = duration + str(m) + ' minutes '
else:
duration = duration + str(m) + ' minute '
if s > 0:
if s > 1:
duration = duration + str(s) + ' seconds.'
else:
duration = duration + str(s) + ' second.'
print(duration)