The average would be
(lap1 + lap2)/2
you would have to add the lap times as milliseconds then take the result and
recreate the minutes:seconds:milliseconds format
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
If you use format
minutes:seconds:milliseconds
and show
00:02:20
do you mean
00:02:200
vegaseat
DaniWeb's Hypocrite
6,475 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,611
Skill Endorsements: 36
Remember that '/' in Python2 is integer division.
Ahh, corrected line
micro_x = micro_x - seconds * 1000
A few test print help.
You are really using the format minutes:seconds:centiseconds
vegaseat
DaniWeb's Hypocrite
6,475 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,611
Skill Endorsements: 36
00:02:500 # should be 00:02:30
A half a second is 500 milliseconds so 2:500 (== 2.5) is correct
00:03:0 # should be 00:03:30
We don't know what code you are using so how do you expect someone to help? Take vegaseat's suggestion and print the variables total_seconds, millisec, minutes, micro_x, and seconds on the line following each calculation to determine where the error is occurring.
Also, you can use
t1 = lap1.split(":")
def convert_to_int(lap):
t = lap.split(":")
return int(t[0]), int(t[1]), int(t[2])
def lap_average(lap1, lap2):
print convert_to_int(lap1)
print convert_to_int(lap2)
lap_average('03:40:00', '05:20:00')
Print the "t" tuple if you don't know what it will contain.
woooee
Posting Maven
2,705 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
As stated above, I would suggest you add a print statment (after the line quoted below) and compare the output to what it should be, calculated by hand. If it does not come out then break each part down and compare, i.e calculate minutes only and compare and subtract from what total milli-seconds should be if correct giving seconds and milli-seconds remaining, then you can compare seconds and do the same and then milli-seconds (you are dividing and multiplying by 1000 not 100 so milli-second is correct).
hundredths = int(60000 * minutes + 1000 * seconds + 0.001 * centesimos)
So the following, and obviously milliseconds is the problem but you have to get to what they should be verses what they are in some way.
minutes = int(mins1) + int(mins2)
## for the 2nd test ('03:00:02', '02:00:00') = 2:30:01 as median
## = how many milliseconds should your program have
woooee
Posting Maven
2,705 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
Try this:
def lap_average(lap1, lap2):
# get minutes, seconds, centiseconds
m1, s1, c1 = [int(x) for x in lap1.split(':')]
m2, s2, c2 = [int(x) for x in lap2.split(':')]
# form a list of centisecond values
tlist1 = [m1*60*100, s1*100, c1]
tlist2 = [m2*60*100, s2*100, c2]
# get the total centiseconds
centis = sum(tlist1) + sum(tlist2)
# take integer average
centis = centis // 2
# get minutes, seconds from centiseconds
seconds, centis = divmod(centis, 100)
minutes, secs = divmod(seconds, 60)
print('-'*33)
print("Given lap times %s %s" % (lap1, lap2))
print("Average time = %02d:%02d:%02d" % (minutes, secs, centis))
# test times
lap_average('03:40:00', '05:20:00')
lap_average('03:00:02', '02:00:00')
lap_average('02:25:50', '06:50:75')
lap_average('00:02:00', '00:03:00')
lap_average('00:02:20', '00:04:40')
lap_average('02:40:40', '03:30:30')
lap_average('02:60:30', '60:40:40')
''' result ...
---------------------------------
Given lap times 03:40:00 05:20:00
Average time = 04:30:00
---------------------------------
Given lap times 03:00:02 02:00:00
Average time = 02:30:01
---------------------------------
Given lap times 02:25:50 06:50:75
Average time = 04:38:12
---------------------------------
Given lap times 00:02:00 00:03:00
Average time = 00:02:50
---------------------------------
Given lap times 00:02:20 00:04:40
Average time = 00:03:30
---------------------------------
Given lap times 02:40:40 03:30:30
Average time = 03:05:35
---------------------------------
Given lap times 02:60:30 60:40:40
Average time = 31:50:35
'''
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
woooee
Posting Maven
2,705 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
Question Answered as of 4 Months Ago by
woooee,
Ene Uran,
vegaseat
and 1 other