-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplits.py
More file actions
executable file
·133 lines (108 loc) · 4.39 KB
/
splits.py
File metadata and controls
executable file
·133 lines (108 loc) · 4.39 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import re
def intro():
print('\nThis \"Split Calulator\" will take a variable number of splits')
print('given by you and display the full time back. For example, if you')
print('input 4 splits of 52 seconds each, 3:28.00 will be shown. You can')
print('choose between splits all being the same time, or different times.\n')
def recieveInput():
while True:
splitLength = input('Please enter \'same\' for even splits, or \'diff\' for variable length splits: ')
if splitLength == 'same':
sameSplits()
break
elif splitLength == 'diff':
diffSplits()
break
else:
print('\n--Input does not match--\n')
def sameSplits():
splitTalk()
splitCount, splitLength = getSplitInfo(False)
splitList = parseLength(splitLength)
hours, minutes, seconds = calculateTime(splitCount, splitList, False)
printTime(hours, minutes, seconds)
def diffSplits():
splitTalk()
print('A prompt will pop up for each split you\'d like to compute\n')
#splitLength is a list of lists in this case, since each split is different
splitCount, splitLength = getSplitInfo(True)
lol = []
for i in range(int(splitCount)):
splitList = parseLength(splitLength[i])
lol.append(splitList)
h, m, s = calculateTime(splitCount, lol, True)
printTime(h, m, s)
def splitTalk():
print('\nEnter the number of splits and your split time below. You can enter your split')
print('time with lower case m, and/or s, such as 6m 12s. You can also enter the split')
print('in stopwatch notation, such as 6:12')
print('This Calculator does not take splits longer than 1 hour\n')
def getSplitInfo(diff):
while True:
try:
splitCount = int(input('How many splits are we working with? '))
break
except ValueError:
print('Input entered is not a number. Please try again')
if diff:
lol = []
for i in range(int(splitCount)):
while True:
splitLength = input('Enter your split time here: ')
if 'm' not in splitLength and 's' not in splitLength and ':' not in splitLength:
print('Incorrect format used. Please try again')
else:
lol.append(splitLength)
break
return splitCount, lol
else:
while True:
splitLength = input('Enter your split time here: ')
if 'm' not in splitLength and 's' not in splitLength and ':' not in splitLength:
print('Incorrect format used. Please try again')
else: break
return splitCount, splitLength
def parseLength(splitLength):
# Split on either an m, s, or colon for the time
splitList = re.split('m |s|:', splitLength)
while '' in splitList:
splitList.remove('')
return splitList
def calculateTime(splitCount, splitList, diff):
initialMinutes = initialSeconds = -1
countedMinutes = countedSeconds = hours = 0
if len(splitList) == 2:
initialMinutes = int(splitList[0])
initialSeconds = int(splitList[1])
elif len(splitList) == 1:
initialSeconds = int(splitList[0])
if diff:
for l in splitList:
if len(l) > 1:
countedMinutes = countedMinutes + int(l[0])
countedSeconds = countedSeconds + int(l[1])
if len(l) == 1:
countedSeconds = countedSeconds + int(l[0])
else:
for split in range(splitCount):
if initialMinutes != -1:
countedMinutes = countedMinutes + initialMinutes
if initialSeconds != -1:
countedSeconds = countedSeconds + initialSeconds
if countedSeconds > 60:
countedMinutes = countedMinutes + (countedSeconds // 60)
countedSeconds = countedSeconds % 60
if countedMinutes > 60:
hours = countedMinutes // 60
countedMinutes = countedMinutes % 60
return hours, countedMinutes, countedSeconds
def printTime(hours, minutes, seconds):
if minutes == 0:
print('\nTotal time is:\t{} SECONDS\n'.format(seconds))
elif hours == 0:
print('\nTotal time is:\t{} MINUTES {} SECONDS\n'.format(minutes, seconds))
else:
print('\nTotal time is:\t{} HOURS {} MINUTES {} SECONDS\n'.format(hours, minutes, seconds))
if __name__ == '__main__':
intro()
recieveInput()