Nov-15-2019, 02:24 PM
So below my code i have got everything working. However when there is an amount of errors in entering race times for each lane. It adds an extra lane. so if input 4 racers, and within entering the times you put wrong info in. it will end up asking for 5 lanes. Can anyone see why?
counter=0
specTime=0
laneNum=[]
gender = 0
genderList = ["m" ,"M", "f" , "F"]
numRacers= 0
while gender not in genderList:
gender=input("Please enter whether it is a male or female race. M/F ")
worldrecords=[9.58,9.86,9.87]
while gender == "M" or gender == "m":
try:
while (numRacers < 4) or (numRacers > 8):
numRacers= int(input("Please input how many racers will be participating? There's a limit from 4-8 racers. "))
if (numRacers < 4) or (numRacers > 8):
print("Error")
for count in range(numRacers):
specTime=counter+1
time=float(input("Please enter the lap time for lane " +str(specTime)+ " to 2 decimal places. "))
num=round(time, 2) # turns the time into two decimal places if the user has put more than two DP
laneNum.append(num)
if laneNum[counter]< worldrecords[0]:
print("Congratulations! World record, European record and British record has been achieved!")
elif laneNum[counter]< worldrecords[1]:
print("Congratulations! European record and British Record has been achieved!")
elif laneNum[counter]< worldrecords[2]:
print("Congratulations! British record has been achieved!") # the above if statements will notify the user if a record has been achieved when the time is inputted
counter=counter+1
laneNum.sort() #This will order the inputed race times from fastest to slowest.
print(laneNum)
except:
print("Error")
continue # the above validation will only allow the user to input numbers 4-8, anything else entered will prompt the user to re enter a number
break
worldrecords2=[10.49,10.73,10.99]
while gender == "F" or gender == "f":
try:
while (numRacers < 4) or (numRacers > 8):
numRacers= int(input("Please input how many racers will be participating? There's a limit from 4-8 racers. "))
if (numRacers < 4) or (numRacers > 8):
print("Error")
for count in range(numRacers):
specTime=counter+1
time=float(input("Please enter the lap time for lane " +str(specTime)+ " to 2 decimal places. "))
num=round(time, 2) # turns the time into two decimal places if the user has put more than two DP
laneNum.append(num)
if laneNum[counter]< worldrecords2[0]:
print("Congratulations! World record, European record and British record has been achieved!")
elif laneNum[counter]< worldrecords2[1]:
print("Congratulations! European record and British Record has been achieved!")
elif laneNum[counter]< worldrecords2 [2]:
print("Congratulations! British record has been achieved!") # the above if statements will notify the user if a record has been achieved when the time is inputted
counter=counter+1
laneNum.sort() #This will order the inputed race times from fastest to slowest.
print(laneNum)
except:
print("Error")
continue # the above validation will only allow the user to input numbers 4-8, anything else entered will prompt the user to re enter a number
break
