Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Race Results Your best friend has organized a 5K race. Minutes before the race s

ID: 3717627 • Letter: R

Question

Race Results

Your best friend has organized a 5K race.   Minutes before the race started, the timing equipment broke, so he was forced to time the race by with a stopwatch.

The stopwatch was started at the beginning of the race.   As each runner finished your friend wrote down the time showing on the watch.   Your job is to take this data and determine the 1st, 2nd, and 3rd winners of each category: Men, Women, Under 30, 40-60, and over 60.

Two files are provided.   Racers.dat contains the bib number, name, age, and gender of each racer.   Times.dat contains the bib number and times recorded at the finish line.   Your output should look similar to this:

RACE RESULTS

Men:

2760      Eli Griffis                 22:09

2042      Ken Grisback           22:30

776        Stephen Hinckley   22:45

Women:

2813      Keely McCarthy        23:55

2669      Jada Atchison         23:57

2719      Caroline Dee           27:50

Age under 30:

2504      Omar Rodriguez      23:56

2635      Leland Taylor          23:56

2669      Jada Atchison         23:57

Age 30 - 59:

2760      Eli Griffis                 22:09

2042      Ken Grisback           22:30

776        Stephen Hinckley   22:45

Age 60 and over:

2995      Michael Doremus 31:32

2877      Dale Umholtz          39:36

2849      Maria Ramirez        41:51  

Hint: As you read the times from the file convert them in MM:SS format, convert them to a single number - seconds since the start of the race.   Convert them to MM:SS format as needed for printing.

LANGUAGE PYTHON

Explanation / Answer

'''

written in python 2.7

data.txt file format:

id name time

each value is separated with

Sample data.txt:

Men:

2760 Eli Griffis 22:09

2042 Ken Grisback 22:30

776 Stephen Hinckley 22:45

Women:

2813 Keely McCarthy 23:55

2669 Jada Atchison 23:57

2719 Caroline Dee 27:50

Age under 30:

2504 Omar Rodriguez 23:56

2635 Leland Taylor 23:56

2669 Jada Atchison 23:57

Age 30 - 59:

2760 Eli Griffis 22:09

2042 Ken Grisback 22:30

776 Stephen Hinckley 22:45

Age 60 and over:

2995 Michael Doremus 31:32

2877 Dale Umholtz 39:36

2849 Maria Ramirez 41:51  

'''

f = open("data.txt","r")

x = f.readline()

data=[]

category = []

pos = -1

while(x):

#Start of while

spl = x.strip().split(" ")

l = len(spl)

if(l==1):

#start of if

data.append([])

category.append(spl[0])

pos+=1

#end of if

elif(l==3):

#start of elif

data[pos].append(spl)

#end of elif

else:

#start of else

print "Missing or having more than 3 values at ",x,"Continuing scannin"

#end of else

x=f.readline()

for i in xrange(pos+1):

#start of for

max1 = -1

pos1 = -1

max2 = -1

pos2 = -1

max3 = -1

pos3 = -1

for j in xrange(len(data[i])):

#start of for

mins,sec = map(int,data[i][j][2].strip().split(':'))

time_in_sec = mins*60+sec

if(max1<time_in_sec):

#start of if

max3 = max2

pos3 = pos2

max2 = max1

pos2 = pos1

max1 = time_in_sec

pos1 = j

#end of if

#end of for

print category[i],"Winners ================= "

print "1st place ","Id :",data[i][pos1][0],"Name :",data[i][pos1][1],"Time Taken :",data[i][pos1][2]

print "2nd place ","Id :",data[i][pos2][0],"Name :",data[i][pos2][1],"Time Taken :",data[i][pos2][2]

print "3rd place ","Id :",data[i][pos3][0],"Name :",data[i][pos3][1],"Time Taken :",data[i][pos3][2]

print "======================="

#end of for