average time calculation??

pmec pcurad01 at gmail.com
Thu Jan 10 15:31:10 EST 2013


Hi Oscar, again I do apologize for my beginner mistakes, I've changed the code taking in consideration some of your and MRAB suggestions.

Could you give me an example on how could I use the datetime.timedelta function in this particular case. 

This is my code:


def lap_average(lap1, lap2):

    mins1, secs1, hundreths1 = lap1.split(":")
    mins2, secs2, hundreths2 = lap2.split(":")
    
    minutes = int(mins1) + int(mins2)
    seconds = float(secs1) + float(secs2)
    hundredths = int(60000 * minutes + 1000 * seconds)
    hundredths = hundredths // 2

    print hundredths
    
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') #should output: 00:02:50
lap_average('00:02:20', '00:04:40') # 00:03:30
lap_average('02:40:40', '03:30:30') # etc
lap_average('02:60:30', '60:40:40')



Also I was a bit confused with what you said about :


"> total_seconds = int(secs1) + int(secs2) + int(mins1) * 60 + int(mins2) * 60 

What happened to the hundredths in the line above. Surely you wanted 
to add 0.01 * hundredths there."


I thought the above was already the entire time as hundredths of second??



More information about the Python-list mailing list