for example if i have 00:02:20 and 00:04:40 (minutes:seconds:hundredths) it should return 00:03:30
i was able to get the minutes and the seconds just fine but i am going desperately crazy in trying to get the hundredths of seconds right.
here is the code:
def lap_average(lap1, lap2): mins1, secs1, hundred_sec1 = lap1.split(":") mins2, secs2, hundred_sec2 = lap2.split(":") minutes = int(mins1) + int(mins2) seconds = float(secs1) + float(secs2) h_seconds = float(hundred_sec1) + float(hundred_sec2) hundredths = int(60000 * minutes + 1000 * seconds + 0.001 * h_seconds) hundredths = hundredths // 2 secs, hundredths = divmod(hundredths, 1000) minutes, secs = divmod(secs, 60) hundredths = ((hundredths/1000)*1000) print minutes, secs, hundredths # testing 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')
Any help in achieving this would be much appreciated.
P.S - please be nice i'm a newbie