-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswim_time_calculator.py
91 lines (81 loc) · 2.29 KB
/
swim_time_calculator.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#main function for doing the calculations
def calculateTime(hour,min,sec, num):
#checks if hour,min and sec are empty
if(hour == ""):
hour = "00"
if(min == ""):
min = "00"
if(sec == ""):
sec = "00"
#gets the value of each unit times the number of rounds
sec = num * int(sec)
min = num * int(min)
hour = num * int(hour)
#if sec or min are over 60 seconds/minutes we will get the equivalent for minutes/hour
secTemp = int(sec / 60)
min = min + secTemp
minTemp = int(min / 60)
hour = hour + minTemp
#this takes out only the seconds if the seconds add up to more than a minute the minutes
# are stored in min
sec = sec % 60
#this takes out only the minutes if the minutes add up to more than an hour the hours
# are stored in hour
min = min % 60
#if any of the values are a single digit we add a zero in the front and string it
if sec < 10:
sec = "0" + str(sec)
if min < 10:
min = "0" + str(min)
if hour < 10:
hour = "0" + str(hour)
#makes a string of the total time
time = str(hour) + ":" + str(min) + ":" + str(sec)
return time
#add two times together and return the total time
def addTime(time1, time2):
#checks if time1 or time2 are empty
if time1 == "":
time1 = "00:00:00"
if time2 == "":
time2 = "00:00:00"
timeList = [None] * 6
temp = ""
i = 0
for letter in time1:
if letter == ":":
temp = ""
i += 1
else:
temp = temp + letter
timeList[i] = temp
temp = ""
i += 1
for letter in time2:
if letter == ":":
temp = ""
i += 1
else:
temp = temp + letter
timeList[i] = temp
j = 0
while j < 3:
timeList[j] = int(timeList[j]) + int(timeList[j+3])
j += 1
sec = timeList[2]
min = timeList[1]
hour = timeList[0]
secTemp = int(sec / 60)
min = min + secTemp
minTemp = int(min / 60)
hour = hour + minTemp
sec = sec % 60
min = min % 60
if sec < 10:
sec = "0" + str(sec)
if min < 10:
min = "0" + str(min)
if hour < 10:
hour = "0" + str(hour)
time = str(hour) + ":" + str(min) + ":" + str(sec)
return time