vendredi 16 mars 2018

What is causing the function to fail. I type in -5000.00 for latitude and it passes the condition when it shouldn't

My function:

def validInput(floatVal, currInput):
    if currInput == 'latquad_user' :
        if (floatVal >=-109.05 and floatVal <=-102.05):
            return False
        else:
            return True
    elif currInput == 'lngquad_user':
        if floatVal < 37 and floatVal > 41:
            return False
        else:
            return True
    else:
    return False

When I ask the user to input a latitude it is inputted at -5000.0

boo = False


latquad_user = input("Enter lat ")

while(boo == False):
    if(validInput(float(latquad_user),'latquad_user') == True):
        boo = True
    else:
        boo = False
        latquad_user = input("Enter latitude: ")


#assume float values
lngquad_user = input("Enter long: ")

while(boo == False):
    if(validInput(latquad_user,'lngquad_user') == True):
        boo = True
    else:
        boo = False
        latquad_user = input("Enter long: ")

So it runs and asks the user for input, then -5000.0 or something out of bounds is enter. For some reason it is returning true. I have no idea why. Maybe some simple arithmetic mistake.

Thank you

Aucun commentaire:

Enregistrer un commentaire