mercredi 14 janvier 2015

Why is this while loop not running when invalid input is entered more than once?

I have this script that uses a function to retrieve values from the user. I am relatively new to python, but not so new to java and c#/c++, and wanted to try out python for my work. I am a cadastral mapper attempting to use a script to speed up the creation of traverses in ArcMap. The built in part of the program is slooooooooow, and this works faster for me.


Here's the while loop section:



if lineType == 'DD': # direction distance
bearing = str(raw_input("Enter the bearing (N/Sdeg-min-secE/W): "))
bearing = string.upper(bearing)
if 'E' or 'W' in bearing[0]:
while bearing != ' ':
print('Bearings cannot start with east or west.\n')
bearing = str(raw_input("Enter the bearing (N/Sdeg-min-secE/W): "))
bearing = string.upper(bearing)
if 'N' or 'S' in bearing[0]:
break
distance = str(raw_input("Enter the distance: "))


It is set to retrieve the values for the line type DIrection/Distance, and the bearing is formatted as N/S degrees-minutes-seconds E/W. The loop with the if statements are supposed to catch if East or West is in bearing[0]. It catches it the first time, however if you input the same error, i.e. East or West at bearing[0], it breaks the loop and asks for the distance after only one iteration. Why is this????? I have searched EVERYWHERE to find an answer, but I can't find any while loops for a portion of a string.... Please help!


The script is crazy long with copy and pasting minor changes, so if you need the rest, just tell me.


Aucun commentaire:

Enregistrer un commentaire