Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with basic python
#1
Hi everyone, im having trouble with some basic code. basically im having a few errors in the code asking questions twice or not picking up certain information. if someone can help it will be greatly appreciated

the programme needs to allow someone to enter gender, amount of racers, to sort times fastest to slowest and notify if a record is broken.
counter=0                                    
specTime=0                                   
laneNum=[]
gender = 0
genderList = ["m" ,"M", "f" , "F"]


while gender not in genderList:
    gender=input("Please enter whether it is a male or female race. M/F ")

    if gender=="M" or "m":
        worldrecords=[9.58,9.86,9.87]
    while True:
        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("The minimum racers allowed is 4, and the maximum is 8. Please enter the correct racers again")
            continue
        break
        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!")
            counter=counter+1
            laneNum.sort()
            print(laneNum)

if gender=="F" or "f":
    worldrecords2=[10.49,10.73,10.99]
    while False:
            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("The minimum racers allowed is 4, and the maximum is 8. Please enter the correct racers again")
                continue
            break
    while counter!=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!")
        counter=counter+1
        laneNum.sort()
        print(laneNum)
Reply
#2
Line 11 will not do what you expect. Change to
if gender in ["M","m"]:
Likewise change line 34.
Also, if I understand your code correctly, you should de-indent the 19-32 block (and its parallel) so that block is outside the while True loop.
Reply
#3
(Nov-14-2019, 02:38 PM)jefsummers Wrote: Line 11 will not do what you expect. Change to
if gender in ["M","m"]:
Likewise change line 34. Also, if I understand your code correctly, you should de-indent the 19-32 block (and its parallel) so that block is outside the while True loop.

So i have done that, however what i was wanting was if M or m is not entered, it repeats the question until M or M, or F/f is entered
Reply
#4
Ah. So that loop should only be lines 8 and 9.
De-indent everything from line 11 down so that code is not in the "bad gender" while loop
Reply
#5
(Nov-14-2019, 02:52 PM)jefsummers Wrote: Ah. So that loop should only be lines 8 and 9. De-indent everything from line 11 down so that code is not in the "bad gender" while loop

THANKS, ive been racking my brain for the past hour for that simple fix.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020