lundi 2 février 2015

Why if statement to test for correct notation in Deg Min Sec ignoring condition?

I have a script with multiple functions, one of them taking the bearing for a direction distance traverse in ArcMAP, and tests to make sure the input follows the standard guidelines for Degrees Minutes Seconds. It checks for the North South and East West just fine, but when it gets to the actual numerical values for the direction, it fails when I enter N88-12-9E and goes to my conditional statement for "seconds cannot be greater than 60."


The code strips the N/S E/W from the beginning and end of the string, then removes the '-' with a split. Leaving a list of 3 numbers. In the case above, it leaves ['88', '12', '9'] where 9 is the seconds, 12 minutes, 88 degrees.


Here's the small tidbit of code with the if statement:



if dmSplit[1] >= '60' or dmSplit[-1] >= '60':
while dmSplit[1] >= '60':
print("\nMinutes must be less than 60.")
bearing = str(raw_input("Enter the bearing (N/Sdeg-min-secE/W): "))
bearing = string.upper(bearing)
dms = bearing.strip('NSEW')
dmSplit = dms.split('-', 2)
while dmSplit[-1] >= '60':
print("\nSeconds must be less than 60.")
bearing = str(raw_input("Enter the bearing (N/Sdeg-min-secE/W): "))
bearing = string.upper(bearing)
dms = bearing.strip('NSEW')
dmSplit = dms.split('-', 2)


Above that it processes the original split/strip before getting to the first iteration. I don't understand why when I input a valid DMS bearing, it responds with my error check...


Aucun commentaire:

Enregistrer un commentaire