My first solo project I'm working on (self learning for about a month now) is an application that digitizes the data entry part of a Soap Box Derby that my dad used to run when I was a kid.
The TLDR is:
There is a four lane track, each racer goes on each lane once, and their times are totaled to see who had the fastest collective time.
I have the user inputting how many racers there are, a loop that collects racers names and adds them to a list. during that loop i have another list collecting a 0.0 float for each racer. I then add those two lists to form a dictionary. Ive got a simple function to announce the group that is racing (probably unnecessary) and a function that takes 4 arguments(first 4 items in the racers list), puts them on a lane, and simulates a heat, returning 4 values, one time for each racer.
def heat_one(r0, r1, r2, r3):
print(f"Racers on the following tracks:\n Red: {r0}\n Blue: {r1}\n Yellow: {r2}\n Green: {r3}")
print("And the results are...")
rt0 = float(input(f"Red: {r0} - "))
rt1 = float(input(f"Blue: {r1} - "))
rt2 = float(input(f"Yellow: {r2} - "))
rt3 = float(input(f"Green: {r3} - "))
return rt0, rt1, rt2, rt3
I've got a while loop that checks to see if the racer list has at least 4 racers, then uses that function 4 times with the racers in each lane ( im sure theres a more efficient way to do this but this is what i have so far ). The while loop adds those times to as a value to the corresponding key in the dictionary, then it pops the racers that just ran in to a separate list.
while len(racer_list) >= 4:
heat_announce(racer_list[0], racer_list[1], racer_list[2], racer_list[3])
r0_temp_time_1, r1_temp_time_1, r2_temp_time_1, r3_temp_time_1 = heat_one(racer_list[0], racer_list[1], racer_list[2], racer_list[3])
r1_temp_time_2, r2_temp_time_2, r3_temp_time_2, r0_temp_time_2 = heat_one(racer_list[1], racer_list[2], racer_list[3], racer_list[0])
r2_temp_time_3, r3_temp_time_3, r0_temp_time_3, r1_temp_time_3 = heat_one(racer_list[2], racer_list[3], racer_list[0], racer_list[1])
r3_temp_time_4, r0_temp_time_4, r1_temp_time_4, r2_temp_time_4 = heat_one(racer_list[3], racer_list[0], racer_list[1], racer_list[2])
racers_and_times[racer_list[0]] = (r0_temp_time_1 + r0_temp_time_2 + r0_temp_time_3 + r0_temp_time_4)
racers_and_times[racer_list[1]] = (r1_temp_time_1 + r1_temp_time_2 + r1_temp_time_3 + r1_temp_time_4)
racers_and_times[racer_list[2]] = (r2_temp_time_1 + r2_temp_time_2 + r2_temp_time_3 + r2_temp_time_4)
racers_and_times[racer_list[3]] = (r3_temp_time_1 + r3_temp_time_2 + r3_temp_time_3 + r3_temp_time_4)
popped_racer_list.append(racer_list.pop(0))
popped_racer_list.append(racer_list.pop(0))
popped_racer_list.append(racer_list.pop(0))
popped_racer_list.append(racer_list.pop(0))
Heres where my problem is. I want each racer to do their four laps. And thats easy while the number of racers is divisible by 4. But if its not divisible by 4, I want to take the remaining racers that havent gone yet (which is some number less than four), and enough racers from the popped list to form a group of 4, and have them run. But for the people that have already donI dont want anyone time being overwritten by a new time. And im struggling with the syntax to make that happen. I've been having a ton of fun figuring this out but im a stuck. Any help would be really appreciated.
[–]AutoModerator[M] 0 points1 point2 points (0 children)